Skip to content

Commit

Permalink
hzuapps#5 hzuapps#78 提交实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
HCJ0HCJ committed Nov 5, 2016
1 parent 974917f commit f29089c
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
53 changes: 53 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902138/EncodingFilter.java
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 jweb/src/edu/hzu/javaweb/labs/se1414080902138/LoginFilter.java
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
}

}
28 changes: 28 additions & 0 deletions jweb/web/1414080902138/failure.jsp
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>

0 comments on commit f29089c

Please sign in to comment.