1

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

  1. 区域设置过滤器
  2. 许可证过滤器
  3. 登录过滤器

该订单在正常情况下工作正常。但是当我连续刷新时,它有时会跳过许可证过滤器(然后执行是:区域设置过滤器 - >登录过滤器)。

有没有办法避免这种情况?即使我不断刷新,顺序也不应该改变。每次都应该按照顺序。

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>

4

0 回答 0