能不能举个例子?
谢谢
----------------解决方案--------------------------------------------------------
这个没人知道吗?
我设置了一个doFilter(),可是它好像不起作用
有没有人指点一下啊?
----------------解决方案--------------------------------------------------------
你不给我看你的web.xml和dodoFilter代码,我想帮也帮不了呀
----------------解决方案--------------------------------------------------------
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>Message Board Authority Filter</filter-name>
<filter-class>AuthorityFilter</filter-class>
<init-param>
<param-name>login</param-name>
<param-value>login.jsp</param-value>
</init-param>
<init-param>
<param-name>notlogin</param-name>
<param-value>login</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Message Board Authority Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
doFilter()
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import pub.util.*;
public class AuthorityFilter implements Filter
{
FilterConfig filterConfig = null;
String login = "login.jsp";
String[] nologin = null;
// 读取初始化配置参数
public void init(FilterConfig config) throws ServletException
{
this.filterConfig = config;
// 读取登录页面连接(在用户没有登录的时候会跳转到该页面)
String login = filterConfig.getInitParameter( "login" );
this.login = login;
// 读取不需要登录的连接
String notlogin = filterConfig.getInitParameter( "notlogin" );
this.nologin = StringUtil.strTokenizer( notlogin, "," );
}
// 处理操作
public void doFilter( ServletRequest request,
ServletResponse response,
FilterChain chain )
throws IOException, ServletException
{
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
// 判断当前请求是否为不需要登录的请求
if( this.nologin!=null )
{
String requri = req.getRequestURI();
for( int i=0; i<nologin.length; i++ )
{
if( requri.indexOf( nologin[i] ) > 0 )
{
chain.doFilter( request, response );
return;
}
}
}
RequestDispatcher dispatcher = req.getRequestDispatcher( login );
dispatcher.forward( request, response );
}
public void destroy()
{
this.filterConfig = null;
this.nologin = null;
}
}
这个函数是没有问题的StringUtil.strTokenizer( notlogin, "," )
不管我的路径是什么,都可以通过,这个doFilter()好像没有起到作用
[此贴子已经被作者于2006-8-19 12:46:56编辑过]
----------------解决方案--------------------------------------------------------
看不明白你的代码的处理过程,但是觉得这样处理权限的思想还不错 -_______________-!!!
----------------解决方案--------------------------------------------------------