Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

java - How do I configure JSF url mappings without file extensions?

Most tutorials propose a default JSF configuration similar to the following web.xml:

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</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>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

With this configuration the corresponding *.xhtml files in my webapp are only found by the Faces Servlet if the corresponding URLs ends with the file extension .jsf (e.g. http://localhost/welcome.jsf). Is it possible to configure web.xml so URLs that do not end with .jsf are also processed as JSF pages using the same *.xhtml files?

In other words I would like to have URLs that do not depend on the server side implementation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use Filter to hide this extension and make your URL SEO friendly. One such implementation of Filter is PrettyFaces.

For example: If you need http://host:port/yourapp/login to resolve with your login.xhtml then in pretty filter configure following way

<url-mapping id="login">
    <pattern> /login </pattern>
    <view-id> /legacy/user/login.jsf </view-id>
</url-mapping>

Have a look at two min video tutorial


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...