首页 > 其他 > 详细

过滤器

时间:2015-11-04 23:00:45      阅读:275      评论:0      收藏:0      [点我收藏+]

public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {

//进入服务器之前
System.out.println("进入服务器之前>>>>");

HttpServletRequest req=(HttpServletRequest) arg0;
req.setCharacterEncoding(encoding);
if(req.getSession().getAttribute("user")==null){
HttpServletResponse res=(HttpServletResponse) arg1;

res.sendRedirect("login.jsp");
}else{
arg2.doFilter(arg0, arg1);
String path=req.getRequestURI();
System.out.println("你请求的路径是:"+path);
System.out.println("<<<<<进入服务器之后");
}
//进入服务器之后
}

 


public class MyFilter implements Filter {

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
System.out.println("进入Filter");
arg2.doFilter(arg0, arg1);//----->
System.out.println("离开Filter");
}

public void init(FilterConfig arg0) throws ServletException {
System.out.println("初始化");
}

}

 

技术分享

技术分享

过滤器

原文:http://www.cnblogs.com/tian114527375/p/4937639.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!