在web.xml中过滤url模式冲突?

时间:2011-11-04 06:54:11

标签: caching java-ee webpage ehcache web.xml

我正在开发一个项目,应用程序在j2ee中,我已经使用ehcache进行网页缓存但是由于过滤器的条目,它给了我一个错误内容编码错误,我添加了以下过滤器和ehcache.xml可以任何人说哪个条目导致它?

web.xml过滤条目

    <filter>
    <filter-name>SetCharacterEncodingFilter</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>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
    <filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter>
    <filter-name>extensionsFilter</filter-name>
    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
    <init-param>
        <description>Set the size limit for uploaded files.
                   Format: 10 - 10 bytes
                  10k - 10 KB
        </description>
        <param-name>uploadMaxFileSize</param-name>
        <param-value>100m</param-value>
    </init-param>
    <init-param>
        <description>Set the threshold size - files below this limit are stored
             in memory, files above this limit are stored on disk.
                     Format: 10 - 10 bytes
                     10k - 10 KB
        </description>
        <param-name>uploadThresholdSize</param-name>
        <param-value>100k</param-value>
    </init-param>
    <init-param>
        <param-name>uploadRepositoryPath</param-name>
        <param-value>/home</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter>
    <filter-name>CachePage1CachingFilter</filter-name>
    <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter</filter-class>
    <init-param>
        <param-name>suppressStackTraces</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>cacheName</param-name>
        <param-value>CachePage1CachingFilter</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>CachePage1CachingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

ehcache.xml如下

 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">

<diskStore path="java.io.tmpdir"/>
<defaultCache
    maxElementsInMemory="10"
    eternal="false"
    timeToIdleSeconds="5"
    timeToLiveSeconds="10"
    overflowToDisk="true"
/>
<!-- Page and Page Fragment Caches -->
<cache name="CachePage1CachingFilter"
    maxElementsInMemory="10"
    eternal="false"
    timeToIdleSeconds="10000"
    timeToLiveSeconds="10000"
    overflowToDisk="true">
</cache>

编辑: -

我试过,我遇到的问题是因为

中的网址格式
   <filter-name>CachePage1CachingFilter</filter-name>
    <url-pattern>/*</url-pattern> 

在过滤器中,它在过滤器中连续进行,如果我在

后写,则异常是可重入的异常
    <filter-name>CachePage1CachingFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>

它工作正常,但我希望它适用于jsf,jsf的输入在preety配置中完成,如下所示

 <url-mapping id="ManageUsers">
    <pattern>/manageUsers</pattern>
    <view-id>/pages/master/manageUsers.jsf</view-id>
 </url-mapping>

我该怎么做才能避免这种情况?

1 个答案:

答案 0 :(得分:4)

使用servlet spec 2.5(由Tomcat 6实现),您可以指定多个url模式:

<filter-mapping>
    <filter-name>CachePage1CachingFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>

对于2.5之前的版本,您可以指定两个映射

<filter-mapping>
    <filter-name>CachePage1CachingFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>CachePage1CachingFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>