2011-09-22 90 views
4

我在我的頁面命令鏈接看起來像:刪除面servlet的URL模式和頁面擴展從URL

<h:commandLink value="Add user" action="add?faces-redirect=true" /> 

,當我點擊它,它進入網址:

http://localhost:8080/myapp/faces/add.xhtml 

但我想要的網址爲:

http://localhost:8080/myapp/add 

該怎麼做?

我用彈簧3,JSF 2

這是我的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_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 

    <display-name>myapp</display-name> 

    <!-- Add Support for Spring --> 
    <listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
    </listener> 
    <listener> 
    <listener-class> 
     org.springframework.web.context.request.RequestContextListener 
    </listener-class> 
    </listener> 

    <!-- Change to "Production" when you are ready to deploy --> 
    <context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</param-value> 
    </context-param> 

    <!-- Welcome page --> 
    <welcome-file-list> 
    <welcome-file>faces/users.xhtml</welcome-file> 
    </welcome-file-list> 

    <!-- JSF mapping --> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <!-- Map these files with JSF --> 
    <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> 

</web-app> 
+3

爲什麼你有4個'FacesServlet'的URL映射?擺脫所有期待的'* .xhtml',那麼你已經可以縮短到'http:// localhost:8080/myapp/add.xhtml'。要刪除擴展名,只需使用PrettyFaces即可。 – BalusC

回答