JSF 2.2无法正常工作

时间:2017-10-04 12:40:03

标签: java jsf java-ee jsf-2.2

我有一个jsf .xhtml文件。如果我使用doctype

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

2 个答案:

答案 0 :(得分:0)

你放了

<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文件中的

答案 1 :(得分:0)

您可以考虑以下更改:

  1. 使用<!DOCTYPE html>代替<!doctype html> mr mwwolf 建议
  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" >