The servlets named [X] and [Y] are both mapped to the url-pattern [/Z] which is not permitted

时间:2020-12-27 19:12:20

当我用myeclipse新建了一个servlet之后,重新运行tomcat,出现了如下错误

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/task02_2]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
.........


观察错误原因,发现是存在相同的映射,但是web.xml文件里只有一个映射。网上查了之后发现原来是新建servlet时myeclipse在对应的servlet里加了@WebServlet("/UserServlet")注解   这样就不用在web.xml里配置servlet的映射路径了,否则就会出现以上错误。