servlet在tomcat下的配置及冲突

eclipse异常:

严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TomcatTest]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TomcatTest]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 more
Caused by: java.lang.IllegalArgumentException: The servlets named [HelloServlet] and [com.runoob.test.HelloServlet] are both mapped to the url-pattern [/HelloServlet] which is not permitted
    at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:308)
    at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2342)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2024)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1918)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1913)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1913)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1913)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1139)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5066)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

复习了一下servlet

servlet在tomcat下的建立和配置:http://www.runoob.com/servlet/servlet-first-example.html (写的很详细)

对于两种浏览器的url配置(web.xml和注解)以及两种配置的冲突:

servlet浏览器访问路径配置有个小问题:

1、java类里的注解——@WebServlet("/HelloServlet")对应浏览器路径:

http://localhost:8080/TomcatTest/HelloServlet

2、配置文件(we.xml)里对应的浏览器访问路径:

http://localhost:8080/TomcatTest/TomcatTest/HelloServlet

这两种配一个就好了,不然路径重名的话反而会让tomcat启动不了。

例如这样就启动不了

修改web.xml :

/HelloServlet

修改后,web.xml和java累的注解,对应路径都是

http://localhost:8080/TomcatTest/HelloServlet

导致

命名的servlet[HelloServlet]和[com.runoob.test.HelloServlet]都被映射到URL模式[/ HelloServlet]这是不允许的。

解决办法:

注解去掉或者保留注解进入web.xml将映射删除既可以。

 


你可能感兴趣的:(java)