gpt4 book ai didi

caching - 过滤 web.xml 中的 url 模式冲突?

转载 作者:可可西里 更新时间:2023-11-01 12:52:44 28 4
gpt4 key购买 nike

我正在做一个项目,应用程序在 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>

编辑:-

我试过了,我发现问题是因为

中的 url 模式
   <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>

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

最佳答案

使用 servlet 规范 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>

关于caching - 过滤 web.xml 中的 url 模式冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8005807/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com