Skip to content

Commit

Permalink
Merge pull request #593 from qq1032246642/master
Browse files Browse the repository at this point in the history
#4 提交实验代码
  • Loading branch information
zengsn authored Nov 28, 2016
2 parents c49bdb7 + 8c4ab48 commit 44275a4
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 0 deletions.
21 changes: 21 additions & 0 deletions jweb/edu/hzu/javaweb/labs/se1414080902229/se1414080902229.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package se1414080902229;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
* Created by yuan on 2016/11/7.
*/
@WebServlet(value = "/se1414080902229")
public class se1414080902229 extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
response.getWriter().println("servlet 接受成功");
}

protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
doPost(request,response);
}
}
25 changes: 25 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902229/EncodingFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
* Created by yuan on 2016/11/28.
*/
@WebFilter(filterName = "EncodingFilter",urlPatterns = "/*")
public class EncodingFilter implements Filter {
public void destroy() {
}

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
chain.doFilter(req, resp);
}

public void init(FilterConfig config) throws ServletException {

}

}
35 changes: 35 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902229/LoginFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
* Created by yuan on 2016/11/21.
*/
@WebFilter(filterName = "LoginFilter")
public class LoginFilter implements Filter {
public void destroy() {
}

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)resp;
HttpSession session = request.getSession();
String judge = (String)session.getAttribute("login");
if(judge!=null&&judge.equals("1")){
chain.doFilter(req, resp);
}else{
response.sendRedirect("index.jsp");
}
}

public void init(FilterConfig config) throws ServletException {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package se1414080902229;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
* Created by yuan on 2016/11/7.
*/
@WebServlet(value = "/se1414080902229")
public class se1414080902229Servlet extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
response.getWriter().println("servlet 接受成功");
}

protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
doPost(request,response);
}
}
82 changes: 82 additions & 0 deletions labs/1414080902229/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

<script>
function submitClick(){
var xuehao =$("#xuehao").val();
var password =$("#password").val()
if(xuehao==null||xuehao==undefined||xuehao==''){
alert("account is't null");
return ;
}
if(password==null||password==undefined||password==''){
alert("password is't null");
return ;
}
$.getJSON('success.json', function(data){
alert(data.msg);
$("#myModal").hide();
});
}
</script>
</head>

<body>

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
login in
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
account:<input type="text" id="xuehao" name="xuehao" />
password:<input type="password" id="password" name=""password"" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="submit1" onclick="submitClick()" class="btn btn-primary">login</button>
</div>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 44275a4

Please sign in to comment.