我在配置自己第一個struts2的時候,是在myeclipse8.6中創建了一個新的Web Project,然后WebRoot/WEB-INF下的web.xml是自動生成的,xml頭文件信息為:
<?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">
當我把配置struts2的代碼填進去之后,竟然報錯:
1.struts2代碼:
<display-name>我的第一個struts2程序</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>
2.報錯:
Multiple annotations found at this line:
- cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content
type is element-only.
后來發現,並不是struts2配置代碼有問題,而是xml頭文件中,第三行有問題:
xmlns="http://java.sun.com/xml/ns/javaee"
可能是一直用j2ee習慣?反正改成j2ee之后就好了。