2013-05-31 32 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