我需要帮助弄清楚为什么我的过滤器以这种方式链接到* .jsf请求:
filter1-> filter3-> filter2
这种方式用于* .jsp请求(所需的链):
filter1-> filter2-> filter3
<filter>
<display-name>filter1</display-name>
<filter-name>filter1</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<display-name>filter2</display-name>
<filter-name>filter2</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<display-name>filter3</display-name>
<filter-name>filter3</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>filter1</filter-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>filter2</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>filter2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>filter3</filter-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jsf</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
答案 0 :(得分:1)
原始问题是由过滤器优先于Faces servlet引起的。尽管filter2是一个过滤器,但它也与Faces Servlet相关联,因此在所有其他过滤器之后执行。为了抵消这一点,我将Faces Servlet与我的链的最后一个过滤器filter3。
相关联通过以下映射,.jsp和.jsf现在都按所需顺序执行:filter1-&gt; filter2-&gt; filter3
<filter-mapping>
<filter-name>filter1</filter-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>filter2</filter-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>filter3</filter-name>
<url-pattern>*.jsp</url-pattern> <!-- only .jsp since .jsf will be picked up by faces servlet/filter combo -->
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<filter-mapping> <!-- this gets picked up last because of filter vs. servlet precedence, not because of position in web.xml -->
<filter-name>filter3</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>