How do I configure JSF url mappings without file extensions?

后端 未结 2 582
小鲜肉
小鲜肉 2020-12-14 03:56

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


    javax.faces.DEFAULT_SUFFIX&l         


        
相关标签:
2条回答
  • 2020-12-14 04:05

    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

    0 讨论(0)
  • 2020-12-14 04:26

    you can create url mapping like this create faces-config.xml file in WEB-INF folder

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <faces-config 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-facesconfig_1_2.xsd"
                  version="1.2">
    
       <navigation-rule>
            <from-view-id>/jsf/demoapp</from-view-id>
            <navigation-case>
                <from-outcome>demoapp</from-outcome>
                <to-view-id>/demoapp.xhtml</to-view-id>
            </navigation-case>
       </navigation-rule>
    
    
    </faces-config>

    in web.xml you have to do 2 entries

        <servlet>
            <servlet-name>jsfServlets</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>jsfServlets</servlet-name>
            <url-pattern>/jsf/*</url-pattern>
        </servlet-mapping>

    0 讨论(0)
提交回复
热议问题