原先將web.xml文件頭設置為如下格式
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
但在編譯時就報錯:
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.
- No grammar constraints (DTD or XML Schema)
referenced in the document.
如下圖:
據查是文件頭有錯誤,換個就可以了,可這個文件頭是我從tomcat文件夾下的web.xml中拷貝的,相對於換一個文件頭,我更傾向於從自身上找原因。。
下面簡要說明不換文件頭也可以改正錯誤的方法。
首先說第二條錯誤- No grammar constraints (DTD or XML Schema) referenced in the document.
解決辦法是。。。。ctrl+s,這確實是我的疏忽。。滑稽臉
針對第一條:- cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content type is
element-only.
解決辦法是:將<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" ...中的javaee改為j2ee
如下所示
問題就解決了。。