如何使用Apache Tomcat 7订购过滤器

时间:2015-04-07 07:00:07

标签: java tomcat

我正在使用Spring,maven和Apache Tomcat 7创建一个Java Web项目。在这个项目中,我有一个像这样的web.xml:

<display-name>web</display-name>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- Servlet de Spring. Definimos el Servlet que recibirá todas las peticiones que 
    se realizen a la página -->

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<!-- <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param> -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 

<absolute-ordering>
    <name>encodingFilter</name>
    <name>cors</name>
    <name>springSecurityFilterChain</name>
    <name>FileUploadFilter</name>
</absolute-ordering>

<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>

<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>


<filter>
    <filter-name>cors</filter-name>
    <filter-class>filters.SimpleCorsFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>cors</filter-name>
    <url-pattern>/api/*</url-pattern>
</filter-mapping>

<error-page>
    <location>/error</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/error</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error</location>
</error-page>

当我启动Tomcat时,控制台上会显示以下消息:

org.apache.catalina.deploy.WebXml orderWebFragments
Used a wrong fragment name encodingFilter at web.xml absolute-ordering tag!
org.apache.catalina.deploy.WebXml orderWebFragments
Used a wrong fragment name cors at web.xml absolute-ordering tag! 
org.apache.catalina.deploy.WebXml orderWebFragments
Used a wrong fragment name springSecurityFilterChain at web.xml absolute-ordering tag!

我在Apache Tomcat 6上尝试过相同的操作,但我没有遇到任何问题。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)