JSF 2 使用 HTML 页面而不是 XHTML [英] JSF 2 with HTML pages instead of XHTML

查看:16
本文介绍了JSF 2 使用 HTML 页面而不是 XHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 JSF 设置使用带有 html 扩展名的文件.

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

如果我使用 .xhtml 模式 (<url-pattern>*.xhtml</url-pattern>) 并使用 xhtml 扩展名命名我的文件,页面将正确加载并被解析.

If I use a .xhtml pattern (<url-pattern>*.xhtml</url-pattern>) and name my files with a xhtml extension, the pages load correctly and get parsed.

但是,如果我将其更改为 <url-pattern>*.html</url-pattern> 并使用 .html 扩展名命名文件,则会收到 500 错误:

However, if I change this to <url-pattern>*.html</url-pattern> and naming the files with a .html extension, I get 500 an error:

The server encountered an internal error () that prevented it from fulfilling this request.
Exception: java.lang.NullPointerException

服务器日志:

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
    at com.sun.faces.context.flash.ELFlash.getPhaseMapForReading(ELFlash.java:748)
    at com.sun.faces.context.flash.ELFlash.isEmpty(ELFlash.java:466)
    at com.sun.faces.facelets.util.DevTools.writeVariables(DevTools.java:318)
    at com.sun.faces.facelets.util.DevTools.writeVariables(DevTools.java:208)
    at com.sun.faces.facelets.util.DevTools.debugHtml(DevTools.java:123)
    at com.sun.faces.renderkit.RenderKitUtils.renderHtmlErrorPage(RenderKitUtils.java:1139)
    at com.sun.faces.context.ExceptionHandlerImpl.throwIt(ExceptionHandlerImpl.java:249)
    at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:136)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:680)

这是我的 web.xml 文件:

Here is my web.xml file:

<?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_3_0.xsd" id="WebApp_ID" version="3.0">   
  <display-name>com.test.cms</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</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>

</web-app>

推荐答案

但是,如果我将其更改为 *.html 并使用 .html 扩展名命名文件,则会收到 500 错误

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

您的意思是将物理 .xhtml 文件重命名为 .html 吗?您不应该需要这样做.将它们重命名回 .xhtml 并继续在 URL 中使用 .html.FacesServlet 将自动加载与 URL 关联的正确 XHTML 文件.

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.

如果您真的需要给他们 .html 扩展名,那么您还需要将默认后缀更改为 .html.将以下条目添加到 web.xml 以实现该目的:

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>

另见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆