我使用JSF 2.0建立了网站
所有链接如下所示。
http://www.mywebsite.com/faces/index.xhtml
我想要的是删除/ faces /,以便最终的网址如下所示。
http://www.mywebsite.com/index.xhtml
注意:我希望在传递参数时实现此目的。
此问题与我的previous question
有关我尝试的是更改新过滤器的过滤条件
<filter>
<filter-name>UrlRewrite</filter-name>
<filter-class>com.lab.filter.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewrite</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
以
<filter>
<filter-name>UrlRewrite</filter-name>
<filter-class>com.lab.filter.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewrite</filter-name>
<url-pattern>/</url-pattern> // here made change from /* to /
</filter-mapping>
但它给出了错误。没有显示网页。
我想从之前实现的是mywebsite.com/faces/dr.rajesh到mywebsite.com/dr.rajesh
完整的WEB-INF如下。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<filter>
<filter-name>restrict</filter-name>
<filter-class>com.lab.filter.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>restrict</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>none</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>UrlRewrite</filter-name>
<filter-class>com.lab.filter.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewrite</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
答案 0 :(得分:11)
在您的web.xml中,您只需需要以下网址模式:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
并删除Faces Servlet的其他映射。
在现代JSF版本(&gt; 2.1)中,您根本不需要web.xml中的任何条目,因为它们存在于&#39; on&#39; Faces Servlet通过注释进行解析。
答案 1 :(得分:0)
从WEB-INF web.xml中删除以下内容
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>