我们有 servlet 过滤器,它在 JSF 视图显示之前验证几个会话变量。当使用 handleNavigation(...) 方法在 bean 中调用导航规则时,过滤器不会被调用。我错过了什么吗?任何帮助,将不胜感激。
这是 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
version="2.5">
<display-name>JSF</display-name>
<description>
JSF
</description>
<filter>
<filter-name>myFilter</filter-name>
<filter-class>myFilterClassPath</filter-class>
</filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>pathtoAppServletClass</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- Welcome File List -->
<welcome-file-list>
<welcome-file>welcome.xhtml</welcome-file>
</welcome-file-list>
</web-app>
导航规则是 faces-config.xml:
<navigation-rule>
<navigation-case>
<from-outcome>nextPage</from-outcome>
<to-view-id>/nextPage.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
这是代码bean调用:
FacesContext context = FacesContext.getCurrentInstance();
context.getApplication().getNavigationHandler().handleNavigation(context, null, "nextPage");
感谢您的时间!