3

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>
Suanmeiguo
  • 1,365
  • 3
  • 17
  • 28

3 Answers3

9

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.

KiwiMartin
  • 804
  • 9
  • 15
  • 2
    The annotation does seem to be the reason. If you are using STS for development, it puts the url pattern as an annotation above the class. Just removed the section from web.xml and it works fine now. – Deepak G M Apr 03 '15 at 06:55
1

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.

0

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+

Sudhakar
  • 4,823
  • 2
  • 35
  • 42
  • Thank you Sudhakar, I viewed the web.xml in my war file, it's there and only one servlet.crate. I create another project in Eclipse and code the same program again, it's working now. I don't know it's just weird, everything is just the same as previous project (I checked many times). but this work the previous one doesn't! – Suanmeiguo Feb 07 '13 at 23:47