Servlets with the names [create_subscription] and [servlet.create] both appear in the url template [/ create], which is not allowed

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

Servlets with the names [create_subscription] and [servlet.create] are both mapped to the url template [/ create], which is not allowed

web.xml:

<?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> 
+4
source share
3 answers

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

+9
source

Check out the servlet class. This will be @WebServlet ("/ xyz"). comment on this line and then it should work fine.

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

In fact, when you use @WebServlet ("/ xyz"), it treats the servlet name as the fully qualified name of the servlet. Therefore, tomcat assumes that you have two servlet mappings for the same URL, so it gives you an error.

+1
source

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

If all goes well, maybe change the package declaration from servlet.create to something else, like com.test and re run.

As to why 2 servlets cannot be matched with the same Url pattern

The servlet specification does not explicitly indicate this, but some servers do not allow this. Moreover, having two with the same URL does not, because the URL match to the servlet stops at the first match.

Servlet 2.4 spec PDF See page 85 +

0
source

All Articles