Tomcat中web.xml语句顺序

本文详细解析了Tomcat启动时遇到的XML解析错误,指出错误在于web-app元素及其子元素的不正确顺序,并提供了修正方案,确保XML配置文件遵循DTD规范。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

tomcat不能正常启动,错误如下: org.xml.sax.SAXParseException: The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)". 

===================================================


So for the 2.3 version of the DTD, you have to put the tags in the correct order. You have:
<web-app>   <servlet></servlet>   <servlet-mapping></servlet-mapping>   <servlet></servlet>   <servlet-mapping></servlet-mapping>   <servlet></servlet>   <servlet-mapping></servlet-mapping>   <!-- ... -->   <listener></listener> </web-app> 

But the DTD says it must be:
<web-app>   <listener></listener>   <servlet></servlet>   <servlet></servlet>   <servlet></servlet>   <!-- ... -->   <servlet-mapping></servlet-mapping>   <servlet-mapping></servlet-mapping>   <servlet-mapping></servlet-mapping>   <!-- ... --> </web-app> 

======================================
The error message tells you the order they must be in:


 content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*, filter*,filter-mapping*,listener*,servlet*,servlet-mapping*, session-config?,mime-mapping*,welcome-file-list?,error-page*, taglib*,resource-env-ref*,resource-ref*,security-constraint*, login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)"

Means the order is:
icon (0 or 1 times) display-name (0 or 1 times) description (0 or 1 times) distributable (0 or 1 times) context-param (0 or more times) filter (0 or more times) filter-mapping (0 or more times) listener (0 or more times) servlet (0 or more times) servlet-mapping (0 or more times) session-config (0 or 1 times) mime-mapping (0 or more times) welcome-file-list (0 or 1 times) error-page (0 or more times) taglib (0 or more times) resource-env-ref (0 or more times) resource-ref (0 or more times) security-constraint (0 or more times) login-config (0 or 1 times) security-role (0 or more times) env-entry (0 or more times) ejb-ref (0 or more times) ejb-local-ref (0 or more times) 

==============================


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值