forked from hzuapps/java-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
jweb/src/edu/hzu/javaweb/labs/se1414080902138/EncodingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package edu.hzu.javaweb.labs.se1414080902138; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.annotation.WebFilter; | ||
|
||
/** | ||
* Servlet Filter implementation class EncodingFilter | ||
*/ | ||
@WebFilter(filterName="EncodingFilter",urlPatterns="/*") | ||
public class EncodingFilter implements Filter { | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public EncodingFilter() { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
/** | ||
* @see Filter#destroy() | ||
*/ | ||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
/** | ||
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) | ||
*/ | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
// TODO Auto-generated method stub | ||
// place your code here | ||
// pass the request along the filter chain | ||
System.out.println("EncodingFilter---->>>>Filter¿ªÊ¼"); | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setCharacterEncoding("UTF-8"); | ||
chain.doFilter(request, response); | ||
System.out.println("EncodingFilter---->>>>Filter½áÊø"); | ||
} | ||
|
||
/** | ||
* @see Filter#init(FilterConfig) | ||
*/ | ||
public void init(FilterConfig fConfig) throws ServletException { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
jweb/src/edu/hzu/javaweb/labs/se1414080902138/LoginFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package edu.hzu.javaweb.labs.se1414080902138; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
/** | ||
* Servlet Filter implementation class LoginFilter | ||
*/ | ||
@WebFilter(filterName="LoginFilter",urlPatterns="/jweb/*") | ||
public class LoginFilter implements Filter { | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public LoginFilter() { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
/** | ||
* @see Filter#destroy() | ||
*/ | ||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
/** | ||
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) | ||
*/ | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
HttpServletRequest req = (HttpServletRequest) request; | ||
HttpServletResponse res = (HttpServletResponse) response; | ||
HttpSession session = req.getSession(); | ||
if (session.getAttribute("username") != null) { | ||
chain.doFilter(request, response); | ||
} else { | ||
res.sendRedirect("../failure.jsp"); | ||
} | ||
} | ||
|
||
/** | ||
* @see Filter#init(FilterConfig) | ||
*/ | ||
public void init(FilterConfig fConfig) throws ServletException { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%@ 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 'failure.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"> | ||
--> | ||
|
||
</head> | ||
|
||
<body> | ||
The User name can not be empty. <br> | ||
</body> | ||
</html> |