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

Online Book Mall 11--Backend Login Filter

WBOY
Release: 2016-12-05 13:26:26
Original
1256 people have browsed it

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>
Copy after login

 

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);
	}
}  
Copy after login

  

  

 

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template