Rising Sun

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  148 随笔 :: 0 文章 :: 22 评论 :: 0 Trackbacks
public class SignonFilter implements Filter
{
String LOGIN_PAGE="login.jsp";
protected FilterConfig filterConfig;

//过滤处理的方法
public void doFilter(final ServletRequest req,final ServletResponse res,FilterChain chain)throws IOException,ServletException
{
HttpServletRequest hreq = (HttpServletRequest)req;
HttpServletResponse hres = (HttpServletResponse)res;
HttpSession session = hreq.getSession();
String isLogin="";
try
{
isLogin=(String)session.getAttribute("isLogin");
System.out.print(isLogin);
if(isLogin!=null&&isLogin.equals("true"))
{
System.out.println("在SignonFilter中验证通过");
//验证成功,继续处理
chain.doFilter(req,res);
}
else
{
//验证不成功,让用户登录。
hres.sendRedirect("login.jsp");
System.out.println("被SignonFilter拦截一个未认证的请求");
}

}
catch(Exception e)
{
e.printStackTrace();
}

}

public void setFilterConfig(final FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
}

//销毁过滤器
public void destroy()
{
this.filterConfig=null;
}
/**
*初始化过滤器,和一般的Servlet一样,它也可以获得初始参数。
*/
public void init(FilterConfig config) throws ServletException {
this.filterConfig = config;
}

}


posted on 2006-07-27 15:19 brock 阅读(1376) 评论(1)  编辑  收藏

评论

# re: 关于filter验证用户权限 2016-03-15 13:50 12
333  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: