【问题标题】:JSF 2.2 <!doctype html> not workingJSF 2.2 <!doctype html> 不工作
【发布时间】:2017-10-04 12:40:02
【问题描述】:

我有一个 jsf .xhtml 文件。如果我使用文档类型

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

一切正常。但我想要一个 HTML5 站点。当我添加

<!doctype html>

doctype 我收到这个错误:

error on line 1 at column 2: StartTag: invalid element name

什么问题?

这是我的 web.xml:

<?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">

    <display-name>ZaplianceLogAnalyser</display-name>

    <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>

    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

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

</web-app>

【问题讨论】:

  • 尝试使用 DOCTYPE
  • 您的问题解决了吗?如果是,请接受答案或发布您的解决方案以将问题标记为已关闭

标签: java jsf jakarta-ee jsf-2.2


【解决方案1】:

你放了吗

<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">

在您的 web.xml 文件中?

【讨论】:

  • 是的,这是我的 Web.xml。好的,它太长了...我将粘贴.bin ist
  • 你对这个文件(html)有什么类型的编码?您是否尝试按照@mr mcwolf 的建议使用大写的 DOCTYPE?
【解决方案2】:

您可以考虑以下更改:

  1. 使用&lt;!DOCTYPE html&gt; 而不是&lt;!doctype html&gt;,就像mr mcwolf建议的那样
  2. 将您的 JSF 页面映射到 *.xhtml instead of *.html,除非您已经与该选择一致,但我看到您将您的 javax.faces.DEFAULT_SUFFIX 设置为 .xhtml 并且您正在使用 .xhtml 文件...进一步reading about why .xhtml
  3. 我不确定 web.xml,但我现在习惯在任何地方使用 xmlns.jcp.org 命名空间,而不是 java.sun.com,包括 web.xml 标头:

    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1" >
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 2016-07-04
    • 2011-04-03
    相关资源
    最近更新 更多