【问题标题】:Remove faces servlet url pattern and page extension from url从 url 中删除 faces servlet url 模式和页面扩展名
【发布时间】:2011-11-22 18:28:01
【问题描述】:

我的页面中有一个命令链接,如下所示:

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

当我点击它时,它会转到 url:

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

但我希望网址是:

http://localhost:8080/myapp/add

怎么做?

我正在使用 spring 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>

【问题讨论】:

  • 为什么FacesServlet 有 4 个 URL 映射?摆脱他们对*.xhtml 的期望,然后你已经可以将其缩短为http://localhost:8080/myapp/add.xhtml。要删除扩展,只需使用已回答的 PrettyFaces。

标签: jsf jsf-2 friendly-url


【解决方案1】:

您可以使用PrettyFaces

【讨论】:

    猜你喜欢
    • 2017-05-08
    • 2015-03-20
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2013-03-14
    相关资源
    最近更新 更多