Servlet过滤器链顺序在连续刷新时发生变化

时间:2013-11-04 05:40:55

标签: java servlets filter servlet-filters

在我的应用程序中,我们实现了几个过滤器。例如,我有三个过滤器

  1. 区域设置过滤器
  2. 许可证过滤器
  3. 登录过滤器
  4. 在正常情况下,订单工作正常。但是,当我提供持续刷新时,它有时会跳过许可证过滤器(然后执行:Locale Filter - > Login Filter)。

    有什么方法可以避免这种情况吗?即使我不断刷新,订单也不应该改变。每次都应遵循该命令。

    public class LicenseFilter implements Filter {
    
    @Override
    public void destroy() {
    
    }
    
    
    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
            throws IOException, ServletException {
    
            try {
                        LOGGER.info("In LicenseFilter");    
                        licenseValidator.validate();
                        chain.doFilter(req, res);
                }catch (Exception excep) {  
                         LOGGER.error("License Error " + excep.getMessage());               
                         req.setAttribute("error", excep.getMessage());
                        RequestDispatcher dispatcher = req
                                .getRequestDispatcher("license_list.action");
                        dispatcher.forward(req, res);
                } 
            } 
    
    }
    
    @Override
    public void init(FilterConfig cfg) throws ServletException {
    
        WebApplicationContext wctx = WebApplicationContextUtils.getWebApplicationContext(cfg
                .getServletContext());
        licenseValidator = (licenseValidator) wctx.getBean("licenseValidator");
        ctx = cfg.getServletContext().getContextPath();
    
    }
    

    }

    的web.xml

    xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>web</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>META-INF/beans-*.xml</param-value>
    </context-param>
    
       <filter>
        <filter-name>localeFilter </filter-name>
        <filter-class>com.filter.LocaleFilter</filter-class>
       </filter>
    
    <filter-mapping>
        <filter-name>localeFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
     <filter>
        <filter-name>licenseFilter</filter-name>
        <filter-class>com.filter.licenseFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>licenseFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
     <filter>
        <filter-name>loginFilter</filter-name>
        <filter-class>com.filter.LoginFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>loginFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>   
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    

0 个答案:

没有答案