欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2022-03-21 14:14:03
...
网上图书商城11--后台登录过滤器

1.web.xml

AdminLoginFiltercn.itcast.goods.admin.web.filter.AdminLoginFilterAdminLoginFilter/adminjsps/admin/*/admin/*

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