| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1710 人关注过本帖
标题:doFilter()怎么用啊?
只看楼主 加入收藏
xqiang
Rank: 1
等 级:新手上路
帖 子:291
专家分:0
注 册:2006-2-23
收藏
 问题点数:0 回复次数:4 
doFilter()怎么用啊?
有没有人知道doFilter()是什么东东啊?要怎么用啊?
能不能举个例子?
谢谢
搜索更多相关主题的帖子: doFilter 
2006-08-18 09:58
xqiang
Rank: 1
等 级:新手上路
帖 子:291
专家分:0
注 册:2006-2-23
收藏
得分:0 
这个没人知道吗?
我设置了一个doFilter(),可是它好像不起作用

有没有人指点一下啊?

相信自己可以的!!! http://www.
2006-08-19 08:38
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 

你不给我看你的web.xml和dodoFilter代码,我想帮也帮不了呀


淘宝杜琨
2006-08-19 12:23
xqiang
Rank: 1
等 级:新手上路
帖 子:291
专家分:0
注 册:2006-2-23
收藏
得分:0 

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编辑过]


相信自己可以的!!! http://www.
2006-08-19 12:45
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
看不明白你的代码的处理过程,但是觉得这样处理权限的思想还不错 -_______________-!!!

淘宝杜琨
2006-08-19 15:29
快速回复:doFilter()怎么用啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012286 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved