-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #487 from Darkreunion/master
- Loading branch information
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
jweb/src/edu/hzu/javaweb/labs/se1414080902239/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,32 @@ | ||
package Filter; | ||
|
||
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; | ||
|
||
public class EncodingFilter implements Filter { | ||
|
||
@Override | ||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, | ||
FilterChain chain) throws IOException, ServletException { | ||
request.setCharacterEncoding("UTF-8"); | ||
chain.doFilter(request, response); | ||
} | ||
@Override | ||
public void init(FilterConfig arg0) throws ServletException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
jweb/src/edu/hzu/javaweb/labs/se1414080902239/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,46 @@ | ||
package Filter; | ||
|
||
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.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
public class LoginFilter implements Filter { | ||
|
||
@Override | ||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
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"); | ||
} | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
jweb/src/edu/hzu/javaweb/labs/se1414080902239/Redirectservlet.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,99 @@ | ||
package se; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class S1 extends HttpServlet { | ||
|
||
/** | ||
* Constructor of the object. | ||
*/ | ||
public S1() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Destruction of the servlet. <br> | ||
*/ | ||
public void destroy() { | ||
super.destroy(); // Just puts "destroy" string in log | ||
// Put your code here | ||
} | ||
|
||
/** | ||
* The doGet method of the servlet. <br> | ||
* | ||
* This method is called when a form has its tag value method equals to get. | ||
* | ||
* @param request the request send by the client to the server | ||
* @param response the response send by the server to the client | ||
* @throws ServletException if an error occurred | ||
* @throws IOException if an error occurred | ||
*/ | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
|
||
response.setContentType("text/html"); | ||
PrintWriter out = response.getWriter(); | ||
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); | ||
out.println("<HTML>"); | ||
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); | ||
out.println(" <BODY>"); | ||
out.print(" This is "); | ||
out.print(this.getClass()); | ||
out.println(", using the GET method"); | ||
out.println(" </BODY>"); | ||
out.println("</HTML>"); | ||
out.flush(); | ||
out.close(); | ||
} | ||
|
||
/** | ||
* The doPost method of the servlet. <br> | ||
* | ||
* This method is called when a form has its tag value method equals to post. | ||
* | ||
* @param request the request send by the client to the server | ||
* @param response the response send by the server to the client | ||
* @throws ServletException if an error occurred | ||
* @throws IOException if an error occurred | ||
*/ | ||
public void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
|
||
response.setContentType("text/html;charset=UTF-8"); | ||
String username=request.getParameter("name1"); | ||
String password=request.getParameter("pass1"); | ||
if("abc".equals(username)&&"123".equals(password)) | ||
{ | ||
|
||
response.sendRedirect("main.jsp"); | ||
} | ||
else{ | ||
|
||
|
||
response.sendRedirect("MyJsp.jsp"); | ||
|
||
|
||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
/** | ||
* Initialization of the servlet. <br> | ||
* | ||
* @throws ServletException if an error occurs | ||
*/ | ||
public void init() throws ServletException { | ||
// Put your code here | ||
} | ||
|
||
} |