网上图书商城11--后台登录过滤器

2018-06-22 05:02:19来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

1.web.xml

<filter>
	<filter-name>AdminLoginFilter</filter-name>
	<filter-class>cn.itcast.goods.admin.web.filter.AdminLoginFilter</filter-class>
</filter>
<filter-mapping>
	<filter-name>AdminLoginFilter</filter-name>
	<url-pattern>/adminjsps/admin/*</url-pattern>
	<url-pattern>/admin/*</url-pattern>
</filter-mapping>

 

2.AdminLoginFilter

public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws IOException, ServletException {
	HttpServletRequest req = (HttpServletRequest) request;
	Object admin = req.getSession().getAttribute("admin");
	if(admin == null) {
		request.setAttribute("msg", "您还没有登录,不要瞎遛达!");
		request.getRequestDispatcher("/adminjsps/login.jsp").forward(request, response);
	} else {
		chain.doFilter(request, response);
	}
}  

  

  

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:PHP单线程和多线程调用

下一篇:简单程序题:abcd四个项目收益顺序分别占10%,20%,30%,40%