码迷,mamicode.com
首页 > 其他好文 > 详细

过滤器

时间:2015-11-04 23:02:44      阅读:248      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!