The servlets named [create_subscription] and [servlet.create] are both mapped to the url-pattern [/create] which is not permitted [duplicate]

久未见 提交于 2019-11-28 08:41:34

问题


This question already has an answer here:

  • java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted 6 answers

I am using Tomcat 7 and Eclipse in JDK 7 to create this simple servlet application. But when I copied the war file into tomcat, I cannot start it and get this error:

The servlets named [create_subscription] and [servlet.create] are both mapped to the url-pattern [/create] which is not permitted

the web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>CC</display-name>
  <welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.html</welcome-file>
  <welcome-file>default.htm</welcome-file>
  <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

<servlet>
  <servlet-name>create_subscription</servlet-name>
  <servlet-class>servlet.create</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>create_subscription</servlet-name>
  <url-pattern>/create</url-pattern>
</servlet-mapping>

</web-app>

回答1:


If you have the same mapping declared in both web.xml and in an annotation, you will get this precise error with later versions of Tomcat.




回答2:


Check your servlet class. It would have @WebServlet("/xyz"). comment this line and then it should work fine.

Or you can use it as @WebServlet(value="/create",name="create_subscription")

Actually when you use @WebServlet("/xyz") then it consider the servlet name as fully qualified servlet name. So tomcat think you have two servlet mapping for one URL thats why it gives you error.




回答3:


I doubt that there might be another entry with servlet.create Can you view the web.xml inside the war .

If it turns out okay , probably change the package declaration from servlet.create to something else like com.test and re run .

As to why 2 servlets cannot be mapped to exact same Url pattern

The servlet spec doesnt explicitly state that , but some servers dont allow that. Moreover having two with the exact same URL doesn't make sense because the url to servlet matching stops at the first matching.

Servlet 2.4 spec PDF See p. 85+



来源:https://stackoverflow.com/questions/14714706/the-servlets-named-create-subscription-and-servlet-create-are-both-mapped-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!