Home  >  Article  >  php教程  >  Online Book Mall 11--Backend Login Filter

Online Book Mall 11--Backend Login Filter

WBOY
WBOYOriginal
2016-12-05 13:26:261237browse

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

  

  

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn