网上图书商城11--后台登录过滤器
程序员文章站
2022-03-06 16:21:24
...
1.web.xml
AdminLoginFilter cn.itcast.goods.admin.web.filter.AdminLoginFilter AdminLoginFilter /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); } }