首页 >php教程 >php手册 >网上图书商城11--后台登录过滤器

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

WBOY
WBOY原创
2016-12-05 13:26:261240浏览

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);
	}
}  

  

  

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn