解析XML时出错:未找到元素

问题描述:

在学习JSF并试图在浏览器中打开xhtml页时,我经常发生“解析XML错误:找不到元素”问题。我搜索了web和*为了解决它,但没有解决方案为我工作。解析XML时出错:未找到元素

我对JSF相当陌生,可能会做一些新手的错误。问题出现在我的应用程序中的所有页面,所以我认为我的web.xml可能不正确?

在Ubuntu 14.04上,应用程序服务器是JBoss,浏览器是Firefox。

下面是web.xml中:

<?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" 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>HomeLib</display-name> 
    <welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    </welcome-file-list> 
    <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>/faces/*</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.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</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> 
</web-app> 

而且我的网页具有以下结构:

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

    <h:html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core"> 

    <!-- here goes the content --> 

    </h:html> 

我quess你怎么称呼它是错误的方式。

您在浏览器URL应该是:

主机名:端口/项目名称/面孔模式

你的情况

http://localhost:8080/HomeLib/faces/ 

相当于:

http://localhost:8080/HomeLib/faces/index.xhtml 

面临的URL模式(在你的情况/面/ *)是必要的,以告诉请求的URL应通过FacesServlet的

处理服务器