【问题标题】:Struts2: The markup in the document following the root must be well-formedStruts2:文档中根之后的标记必须格式正确
【发布时间】:2012-12-07 15:41:56
【问题描述】:

我刚刚发现了 Struts2,但 web.xml 文件有问题。

过滤器标签附近出现错误:

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

错误说:在这一行发现了多个注释: - 元素的开始标签&lt;filter&gt; - 根元素之后的文档中的标记必须是正确的 - 形成。

有什么问题?我该如何解决?

谢谢!

感谢 Aleksander 的关注:

这是我的web.xml 文件:

    `<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>struts2example</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>
</web-app>

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

【问题讨论】:

  • 显示整个web.xml文件。
  • 感谢 Aleksandr M,这是我的整个 web.xml 文件

标签: xml struts2 filter markup well-formed


【解决方案1】:

您将标签放在&lt;web-app&gt; 根标签之外。像这样把你的&lt;filter&gt; 放在&lt;web-app&gt; 里面

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>struts2example</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.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

此外,自 Struts 2.1.3 起,org.apache.struts2.dispatcher.FilterDispatcher 已被弃用,请改用 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

【讨论】:

  • 它正在工作!非常感谢亚历山大!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多