web.xml过滤器不会在静态内容上运行

时间:2015-02-13 14:41:07

标签: google-app-engine servlets

有谁知道为什么在提供欢迎文件或任何静态内容时不会运行web.xml过滤器?它似乎只在映射到servlet的URL上运行。如何获取静态内容的过滤功能?

以下是我正在使用的内容:

  <filter>
     <filter-name>myFilter</filter-name>
     <filter-class>com.domain.project.server.service.MyFilter</filter-class>
  </filter>

 <filter-mapping>
    <filter-name>myFilter</filter-name>
    <url-pattern>/*</url-pattern>
 </filter-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

 <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

  <welcome-file-list>
    <welcome-file>WelcomeFile.html</welcome-file>
  </welcome-file-list>

3 个答案:

答案 0 :(得分:1)

耶! This就是这样。为了优化,需要告知愚蠢的应用引擎配置不要绕过你的配置。我将WelcomeFile.html行添加到appengine-web.xml以使其正常工作:

  <!-- Configure serving/caching of GWT files -->
  <static-files>
    <include path="**" />

    <!-- The following line requires App Engine 1.3.2 SDK -->
    <include path="**.nocache.*" expiration="0s" />

    <include path="**.cache.*" expiration="365d" />
    <exclude path="**.gwt.rpc" />
    <exclude path="**WelcomeFile.html" />
  </static-files>

答案 1 :(得分:0)

您可以使用过滤器映射吗?

<filter-mapping>
  <filter-name>myFilter</filter-name>
  <url-pattern>/index.html</url-pattern>
</filter-mapping>

答案 2 :(得分:0)

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String url = ((HttpServletRequest) request).getRequestURI();
        LOGGER.info(url);
        if (url.endsWith(".js") || url.endsWith(".css") || url.endsWith(".html")) {
            chain.doFilter(request, response);
        }
}