创建MyServlet后,在web.xml中对Servlet进行配置后启动tomcat时,tomcat启动报错。
报错内容如下:
Caused by: java.lang.IllegalArgumentException: The servlets named [MyServlet] and [cn.itcast.chapter08.MyServlet] are both mapped to the url-pattern [/MyServlet] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:306)
web.xml
web.xml中添加的内容如下:
去掉web.xml中添加的内容后 可以正常启动; 添加上去就启动失败。
查找原因为:
在自动生成的MyServlet.java中,有一行内容:
@WebServlet("/MyServlet")
使得我们无需手写配置web.xml了
因此,这两个配置只需要保留一个即可。 如果两个都配置了,就会导致tomcat启动失败。