JSF 2 with HTML pages instead of XHTML

后端 未结 2 1599
臣服心动
臣服心动 2020-12-07 03:12

I am trying to get JSF setup to use files with a html extension.

If I use a .xhtml pattern (*.xhtml) and name my

相关标签:
2条回答
  • 2020-12-07 03:26

    As BalusC said you don't need to change the physical file names.

    But anyway I spotted odd values in your web.xml schema. There are mixed version 2_5 and 3_0 values.

    With the settings below you should be able to keep files with .xhtml extension and access them as .html.

    <?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>Development</param-value>
        </context-param>
        <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>*.html</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
        </welcome-file-list>
    </web-app>
    

    I tested it in GlassFish 3.1.2 with Mojarra 2.1.6 and it works fine.

    I hope it helps.

    0 讨论(0)
  • 2020-12-07 03:32

    However, if I change this to *.html and naming the files with a .html extension, I get 500 an error

    Did you mean that you renamed the physical .xhtml files to .html? You should not have the need to do that. Rename them back to .xhtml and keep using the .html in URLs. The FacesServlet will automatically load the right XHTML file associated with the URL.

    If you really need to give them the .html extension, then you'd need to change the default suffix to .html as well. Add the following entry to web.xml to achieve that:

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.html</param-value>
    </context-param>
    

    See also:

    • JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
    • Is it possible to use JSF+Facelets with HTML 4/5?
    0 讨论(0)
提交回复
热议问题