过滤器导致网站变乱
我的登录页面是这样的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE></TITLE><META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK href="css/admin.css" type="text/css" rel="stylesheet"></HEAD><BODY onload=document.form1.name.focus();><TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" bgColor=#002779 border=0> <TR> <TD align=middle> <TABLE cellSpacing=0 cellPadding=0 width=468 border=0> <TR> <TD><IMG height=23 src="images/login_1.jpg" width=468></TD></TR> <TR> <TD><IMG height=147 src="images/login_2.jpg" width=468></TD></TR></TABLE> <TABLE cellSpacing=0 cellPadding=0 width=468 bgColor=#ffffff border=0> <TR> <TD width=16><IMG height=122 src="images/login_3.jpg" width=16></TD> <TD align=middle> <TABLE cellSpacing=0 cellPadding=0 width=230 border=0> <FORM name="login_form" action="servlet/logincheck" method="post"> <TR height=5> <TD width=5></TD> <TD width=56></TD> <TD></TD></TR> <TR height=5> <TD width=5></TD> <TD width=56>登录类型:</TD> <TD> <select name="loginType" style=" width:100px;"> <option value="1">参考人员</option> <option value="2">出题者</option> <option value="3">系统管理员</option> </select> </TR> <TR height=36> <TD></TD> <TD>用户名</TD> <TD><INPUT style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" maxLength=30 size=24 value="admin" name="username"></TD></TR> <TR height=36> <TD> </TD> <TD>口 令</TD> <TD><INPUT style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" type=password maxLength=30 size=24 value="admin" name="password"></TD></TR> <TR height=5> <TD colSpan=3></TD></TR> <TR> <TD> </TD> <TD> </TD> <TD><INPUT type=image height=18 width=70 src="images/bt_login.gif"></TD></TR></FORM></TABLE></TD> <TD width=16><IMG height=122 src="images/login_4.jpg" width=16></TD></TR></TABLE> <TABLE cellSpacing=0 cellPadding=0 width=468 border=0> <TR> <TD><IMG height=16 src="images/login_5.jpg" width=468></TD></TR></TABLE> <TABLE cellSpacing=0 cellPadding=0 width=468 border=0> <TR> <TD align=right><A href="http://www.865171.cn/" target=_blank><IMG height=26 src="images/login_6.gif" width=165 border=0></A></TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>
package cn.hatzhou.servlet;import java.io.IOException;import java.io.PrintWriter;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.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import com.sun.net.httpserver.Filter.Chain;public class LoginFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chian) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); if (session.getAttribute("username") != null) { chian.doFilter(request, response); }else{ request.getRequestDispatcher("index.htm").forward(request, response); } } public void init(FilterConfig arg0) throws ServletException { System.out.println("过滤器初始化"); } }
<filter> <filter-name>LoginFilter</filter-name> <filter-class>cn.hatzhou.servlet.LoginFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>