zoukankan      html  css  js  c++  java
  • 过滤器filter的配置(登陆)

    public class adminFilter implements Filter {
        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
            HttpServletRequest request= (HttpServletRequest) servletRequest;
            HttpServletResponse response= (HttpServletResponse) servletResponse;
            String uri=request.getRequestURI();//获取相对路径
            User user= (User) request.getSession().getAttribute("user");
            if(uri.endsWith("/login.jsp")||uri.endsWith("/login.do")){
                filterChain.doFilter(request,response);
                return;
            }
            if(user!=null){
    
                filterChain.doFilter(request,response);
            }else{
    
                response.sendRedirect("/admin/error/privilege.jsp");
            }
        }
    }
    adminFilter,web.xml中的配置

    <filter>
            <filter-name>adminFilter</filter-name>
            <filter-class>com.bookstore.utils.adminFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>adminFilter</filter-name>
            <url-pattern>/admin/login/*</url-pattern>
            <url-pattern>/admin/notices/*</url-pattern>
            <url-pattern>/admin/orders/*</url-pattern>
            <url-pattern>/admin/products/*</url-pattern>
    
    
        </filter-mapping>
  • 相关阅读:
    解决vs code just-in-time报错的方法
    c++ 右值引用
    c++11 知识点
    ip路由名词介绍&琐碎知识
    第二次结对作业
    软工程第三次作业
    第二次作业
    软件工程第一次作业
    理解Object.defineProperty()
    concat()拷贝的局限性
  • 原文地址:https://www.cnblogs.com/liuna369-4369/p/10930796.html
Copyright © 2011-2022 走看看