2013-05-31 136 views
2

我在下面的XML文件中出现以下错误...我在eclipse上开发了一个小型Struts2 Web应用程序,并且试图查找关于此错误的几篇文章, “网络应用程序”标签中的“过滤器”和“过滤器映射”......但我显示以下错误。以下XML文件有什么问题

The markup in the document following the root element must be well-formed. 

下面是我的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" 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>blah!</display-name> 
<welcome-file-list> 
<welcome-file>index.html</welcome-file> 
<welcome-file>index.htm</welcome-file> 
<welcome-file>index.jsp</welcome-file> 
<welcome-file>default.html</welcome-file> 
<welcome-file>default.htm</welcome-file> 
<welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 

<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
</filter> 

<filter-mapping> 
<filter-name>struts2</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

</web-app> 

什么是这里的问题....我想我已经结束properly..I不能明白这一点

+0

XML中可能有趣的字符?用二进制编辑器查看它? –

+0

treid ...没有发现错误....其他? – uLYsseus

回答

1

尝试增加这个属性解决您的问题重新格式化开始:

<?xml version="1.0" encoding="UTF-8"?> 
    <web-app id="WebApp_9" version="2.4" 
     xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

,并更改节点顺序,像这样的例子:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_9" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

    <display-name>Struts2 Application</display-name> 

    <filter> 
     <filter-name>struts2</filter-name> 
     <filter-class> 
      org.apache.struts2.dispatcher.FilterDispatcher 
     </filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>struts2</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <welcome-file-list> 
     <welcome-file>Login.jsp</welcome-file> 
    </welcome-file-list> 

</web-app> 
+0

我真的不知道是什么原因......但是这个工作完美....你可以把解释原因简短或可以给我任何链接....谢谢一吨! – uLYsseus

+0

是的,没问题。链接:http://viralpatel.net/blogs/tutorial-create-struts-2-application-eclipse-example/ 希望它能帮助你! – gal007

0

的标签,我认为这是不是语法错误。我在这里验证它:http://www.w3schools.com/xml/xml_validator.asp

也许问题在于你处理它的方式。

+0

可以详细说明请求... – uLYsseus

+0

您的XML不是问题。它形成良好。我认为这个错误来自你用来加载这个xml的代码。你能用这些代码编辑你的文章吗? – gal007

+0

它现在的工作......谢谢你:).......我所做的只是重新输入相同的XML代码....清理项目....我真的不知道它为什么工作:哦! – uLYsseus

0

问题是元素顺序的格式良好的文档应该有正确的元素顺序。与

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" 
    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_2_5.xsd"> 
<display-name>blah!</display-name> 

<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
</filter> 

<filter-mapping> 
<filter-name>struts2</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

<welcome-file-list> 
<welcome-file>index.html</welcome-file> 
<welcome-file>index.htm</welcome-file> 
<welcome-file>index.jsp</welcome-file> 
<welcome-file>default.html</welcome-file> 
<welcome-file>default.htm</welcome-file> 
<welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 

</web-app> 
+0

感谢您的回复...它没有工作..显示与上述相同的错误....有什么建议吗? – uLYsseus

0

由于XML文件,你已经向我们表明了我们的格式良好,但是一个令人尊敬的软件说你的XML格式不正确,我会追求这样的假设:它抱怨的XML不是你向我们展示的XML 。

+0

先生...我检查了它....它是同一个文件....我将很快从现在上传我的整个代码 – uLYsseus