Val*_*lva 2 jsf web.xml richfaces jsf-2 servlet-filters
我创建了一个过滤器,它工作正常,但我的richfaces不再正常工作,这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SuaParte</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<context-param>
<param-name>com.sun.faces.disableVersionTracking</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</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>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我也在这里尝试@BalusC建议,将web.xml更改为:
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/secured/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
并将*.xhtml文件更改为文件secured
夹:
但这样过滤器就不再起作用了.
如何使richfaces与我的过滤器一起使用?
RichFaces资源FacesServlet
也通过您的安全过滤器传递.你需要额外的补充if
检查,以绕过资源请求(读:通过完成CSS/JS /图像请求<h:outputStylesheet>
,<h:outputScript>
,<h:graphicImage>
,等,无论是在标记显式声明的或JSF/RichFaces的隐式添加).
String uri = ((HttpServletRequest) request).getRequestURI();
// Ignore JSF2/RF4 resources (which are also mapped on FacesServlet).
if (uri.startsWith(ResourceHandler.RESOURCE_IDENTIFIER) || uri.startsWith(ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER)) {
chain.doFilter(request, response);
return;
}
// ...
Run Code Online (Sandbox Code Playgroud)
同
import javax.faces.application.ResourceHandler;
import org.richfaces.resource.ResourceHandlerImpl;
Run Code Online (Sandbox Code Playgroud)
至于为什么你的/secured/*
映射不起作用是因为你/pages
的文件夹结构中有一个额外的路径.然后应映射过滤器/pages/secured/*
.