Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 以下XML文件中有什么错误_Java_Xml_Struts2 - Fatal编程技术网

Java 以下XML文件中有什么错误

Java 以下XML文件中有什么错误,java,xml,struts2,Java,Xml,Struts2,下面的XML文件有以下错误…我正在eclipse上开发一个小型Struts2 web应用程序,我尝试查找了几篇关于此错误的帖子,并将“filter”和“filter mapping”放在了“web app”标记中…但我显示了以下错误 The markup in the document following the root element must be well-formed. 下面是我的XML文件 <?xml version="1.0" encoding="UTF-8"?> &

下面的XML文件有以下错误…我正在eclipse上开发一个小型Struts2 web应用程序,我尝试查找了几篇关于此错误的帖子,并将“filter”和“filter mapping”放在了“web app”标记中…但我显示了以下错误

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>

废话!
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
支柱2
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
支柱2
/*

这里的问题是什么……我想我已经正确地结束了标记。我无法理解这一点。

我认为这不是语法错误。我在这里验证了它:


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

问题在于元素的顺序格式良好的文档应该具有正确的元素顺序。要解决您的问题,请使用

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

废话!
支柱2
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
支柱2
/*
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp

尝试在开始时添加此属性:

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

Struts2应用程序
支柱2
org.apache.struts2.dispatcher.FilterDispatcher
支柱2
/*
Login.jsp

由于您向我们展示的XML文件格式良好,但有一个值得尊敬的软件说您的XML格式不好,我会继续假设它所抱怨的XML不是您向我们展示的XML。

用下面的代码片段替换标记。

  <web-app 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" version="3.0">


XML中是否有有趣的字符?用二进制编辑器查看它?treid…没有发现错误…还有什么吗?谢谢你的回复…它没有工作..它显示了与上面相同的错误…还有其他建议吗?你的XML不是问题所在。它的格式很好。我认为错误来自于您用来加载此xml的代码。你能用这些代码编辑你的帖子吗?它现在正在工作…谢谢你:)…我所做的就是重新输入相同的xml代码…清理项目…我真的不知道它为什么工作:哦!先生…我已经检查过了…它是同一个文件…我将很快上传我的全部代码,从现在起我真的不知道原因是什么…但这工作非常完美…你能简单地解释一下原因吗,或者你能给我任何指向它的链接吗…谢谢!是的,没问题。链接:希望它能帮助你!