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>
0

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 <servlet-mapping> section from web.xml and it works fine now.
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.

Comments

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+

1 Comment

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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.