【Servlet filter】:
package com.ite.softdev.offical.sysman.signon.web;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.URL;
import com.ite.softdev.offical.common.utility.UtilDebug;/**
* <p>Title: 中国大唐集团本部办公系统平台</p>
* <p>Description:用户登录过滤程序:SignOnFilter.java </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: 长沙亿泰科技有限公司2</p>
* @author [email protected]
* @version 1.0
*/public class SignOnFilter
implements Filter { public static final String module = SignOnFilter.class.getName();
public static final String FORM_SIGNON_URL = "index.jsp";
private FilterConfig Config = null;
//Handle the passed-in FilterConfig
public void init(FilterConfig Config) {
this.Config = Config; } //Process the request/response pair
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
try {
res.setContentType("text/html;charset=GBK");
String strURL = new String( ( (HttpServletRequest) req).
getRequestURL());
if (strURL.endsWith("index.jsp") || strURL.endsWith("不过滤的jsp2.jsp"))
{
//res.sendRedirect("main.jsp");
chain.doFilter(req, res);
}
}
catch (ServletException sx) {
Config.getServletContext().log(sx.getMessage());
}
catch (IOException iox) {
Config.getServletContext().log(iox.getMessage());
}
} /**
public void validateSignOn(ServletRequest req, ServletResponse res,
FilterChain filter) throws IOException, ServletException
{ }
**/
public void destroy() {
this.Config = null; }
}
【jsp]】
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import ="com.ite.softdev.offical.common.utility.Test" %><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<form name="userSignon" action="j_signon_check" method="POST">
<table width="100%" height=100% border="0" align="center" cellspacing="0" cellpadding=0 bgcolor="#ffa600">
<tr>
<td height="100%" width=100% colspan="0" align=center valign=middle>
<table width="770" height="450" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #000000">
<tr>
<td colspan="3" valign="bottom" background="images/signon.jpg" />
<table width="100%" height=150 border="0" cellspacing="2" cellpadding=0>
<tr>
<td align="right" valign="middle">
<font color="#FFFFFF">用户名:</font>
<input name="textfield" type="text" size="10" class="logintext"> <font color="#FFFFFF">
密码:</font> <input name="textfield2" type="password" size="10" class="logintext">
<input type="image" src="images/login.gif" size=3>
<input type="checkbox" value="j_remember_username" size=3> </td>
<td valign="middle" width=60 nowrap></td>
</tr>
</table>
</td>
</tr>
</table> </td>
</tr>
</table>
</form>
</body>
</html>
【xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>SignOnFilter</filter-name>
<filter-class>com.ite.softdev.offical.sysman.signon.web.SignOnFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SignOnFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
package com.ite.softdev.offical.sysman.signon.web;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.URL;
import com.ite.softdev.offical.common.utility.UtilDebug;/**
* <p>Title: 中国大唐集团本部办公系统平台</p>
* <p>Description:用户登录过滤程序:SignOnFilter.java </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: 长沙亿泰科技有限公司2</p>
* @author [email protected]
* @version 1.0
*/public class SignOnFilter
implements Filter { public static final String module = SignOnFilter.class.getName();
public static final String FORM_SIGNON_URL = "index.jsp";
private FilterConfig Config = null;
//Handle the passed-in FilterConfig
public void init(FilterConfig Config) {
this.Config = Config; } //Process the request/response pair
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
try {
res.setContentType("text/html;charset=GBK");
String strURL = new String( ( (HttpServletRequest) req).
getRequestURL());
if (strURL.endsWith("index.jsp") || strURL.endsWith("不过滤的jsp2.jsp"))
{
//res.sendRedirect("main.jsp");
chain.doFilter(req, res);
}
}
catch (ServletException sx) {
Config.getServletContext().log(sx.getMessage());
}
catch (IOException iox) {
Config.getServletContext().log(iox.getMessage());
}
} /**
public void validateSignOn(ServletRequest req, ServletResponse res,
FilterChain filter) throws IOException, ServletException
{ }
**/
public void destroy() {
this.Config = null; }
}
【jsp]】
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import ="com.ite.softdev.offical.common.utility.Test" %><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<form name="userSignon" action="j_signon_check" method="POST">
<table width="100%" height=100% border="0" align="center" cellspacing="0" cellpadding=0 bgcolor="#ffa600">
<tr>
<td height="100%" width=100% colspan="0" align=center valign=middle>
<table width="770" height="450" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #000000">
<tr>
<td colspan="3" valign="bottom" background="images/signon.jpg" />
<table width="100%" height=150 border="0" cellspacing="2" cellpadding=0>
<tr>
<td align="right" valign="middle">
<font color="#FFFFFF">用户名:</font>
<input name="textfield" type="text" size="10" class="logintext"> <font color="#FFFFFF">
密码:</font> <input name="textfield2" type="password" size="10" class="logintext">
<input type="image" src="images/login.gif" size=3>
<input type="checkbox" value="j_remember_username" size=3> </td>
<td valign="middle" width=60 nowrap></td>
</tr>
</table>
</td>
</tr>
</table> </td>
</tr>
</table>
</form>
</body>
</html>
【xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>SignOnFilter</filter-name>
<filter-class>com.ite.softdev.offical.sysman.signon.web.SignOnFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SignOnFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
上面的行改成这样就行了. 不能用 /* 呀.