我正在使用JSF 2.0和Rich Faces 4.0制作网络应用程序 我想知道Web.xml中的最小条目应该是什么,并面向config.xml,以便应用程序能够成功运行。 servlet声明的顺序很重要,我说是因为当我使用自定义安全过滤器运行我的应用程序时,富表面组件有时不会呈现。你能给我一个Web.xml文件示例。
编辑:
* 感谢BalusC *
问题是我何时添加安全过滤器富脸组件未呈现?我感觉到你的web.xml条目和安全过滤器。你能告诉我我在这里做错了吗
</p><p> `<?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>MyApp</display-name>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>classic</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.enableControlSkinning</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.enableControlSkinningClasses</param-name>
<param-value>false</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>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>com.my.SecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>` </p><p> Security Filter </p> <p> `import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ils.core.util.IlsUtil;
/**
* @author --FILTER implementing class; Checks the authentication of every
* request
*/
public class SecurityFilter implements Filter {
public void init(FilterConfig config) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
System.out.println("--------SecurityFilter.doFilter()--------");
boolean redirToLoginPage = false;
HttpServletRequest httpRequest = (HttpServletRequest) request;
InputParamDto parameter = null;
Object user = null;
try {
parameter = (InputParamDto) httpRequest.getSession().getAttribute(
"inputParameter");
} catch (Exception e) {
e.printStackTrace();
}
if (parameter == null || IlsUtil.ifEmpty(parameter.getConsumer_id())) {
redirToLoginPage = true;
}
if (httpRequest.getRequestURI().indexOf("login") == -1
&& redirToLoginPage) {
HttpServletResponse httpResponse = (HttpServletResponse) resp;
httpResponse.setContentType("text/plain");
httpResponse.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
String redirTo = httpRequest.getScheme() + "://"
+ httpRequest.getServerName() + ":"
+ httpRequest.getServerPort()
+ httpRequest.getContextPath() + "/";
httpResponse.setHeader("Location", redirTo);
} else {
chain.doFilter(request, resp);
}
}
public void destroy() {
}
}`</p>
答案 0 :(得分:2)
我的项目中遇到了同样的问题,所以我通过在验证中添加了富表面资源和jsf的路径来解决它。
这样的事情:
String uri = hr.getRequestURI();
if (uri.endsWith(".view")
&& !uri.contains(ResourceHandler.RESOURCE_IDENTIFIER)
&& !uri.contains(ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER)) {
//You put your code here
}
答案 1 :(得分:1)
FacesServlet
中通常的web.xml
映射对于JSF 2.0来说已经足够了。 faces-config.xml
可以留空。 RichFaces 4.0在任一文件中都不需要额外配置。
更新:您需要在不同的网址格式上映射安全过滤器。 RichFaces将动态地在FacesServlet的相同映射中包含CSS / JS文件。但是,您的安全过滤器显然阻止了这些请求(您是不是要注意日志中那些大量的系统输出?)。我建议将安全文件放在一个文件夹中,然后在那里映射过滤器,例如/secured/*
,/private/*
,/app/*
等
与此问题无关,您已经了很多 FacesServlet
映射。请保持清洁并坚持下去。我个人推荐*.xhtml
。这样,只需编辑浏览器地址栏中的URL,endusers将无法再查看原始JSF源。