问题1:配置完web.xml文件后部署到Tomcat时报错。错误信息显示如下:
严重: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myshopping]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441)
*****************************此处略去若干行*******************************************
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
Caused by: java.lang.IllegalArgumentException: The servlets named [GoHallUI] and [com.syj.controller.GoHallUI] are both mapped to the url-pattern [/GoHallUI] which is not permitted
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMappingDecoded(WebXml.java:328)
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:321)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2391)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2068)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1954)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1948)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1948)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1948)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1153)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:775)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5095)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 38 more
五月 26, 2017 3:44:52 下午 org.apache.catalina.startup.HostConfig deployDirectory
严重: Error deploying web application directory [C:\Apache Software Foundation\Tomcat 9.0\webapps\myshopping]
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myshopping]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
*********************************此处再略去若干行**********************************************
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
问题分析:如以上错误信息中有这样一句话值得特别注意,如下:
Caused by: java.lang.IllegalArgumentException: The servlets named [GoHallUI] and [com.syj.controller.GoHallUI] are both mapped to the url-pattern [/GoHallUI] which is not permitted这句话大致的意思是“非法数据异常:名字叫做‘A’和名字叫做‘B’的两个servlet同时映射到了一个url-pattern,这是不允许”。 经过查阅资料发现,造成这种情况的原因可能是使用了MyEclipse中自带的new->servlet功能,IDE在你使用创建功能的时候估计就顺便创建了一个配置文件,如果直接创建一个servlet估计不会出现这种错误。当然以上纯属猜测。 根本原因应该是servlet3.0新特性造成的。
解决办法:在web.xml文件中设置metadata-complete="true" ,只让这一个配置文件生效就可以了。具体如下。
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true" version="3.0">