具有HTML页面而不是XHTML的JSF 2 [英] JSF 2 with HTML pages instead of 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>
另请参见:
- JSF Facelets:有时我看到URL是.jsf,有时是.xhtml.为什么?
- 是否可以将JSF + Facelets与HTML 4/5?
- JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
- Is it possible to use JSF+Facelets with HTML 4/5?
See also:
这篇关于具有HTML页面而不是XHTML的JSF 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!