Search code examples
eclipsetomcatservletsillegalargumentexceptionservlet-mapping

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


When ever I try to execute certain files in my Project I get this error

"Server Tomcat v7.0 Server at localhost failed to start"

The console shows following errors

Caused by: java.lang.IllegalArgumentException: The servlets named [AdminValidate] and [com.kunal.servlet.AdminValidate] are both mapped to the url-pattern [/AdminValidate] which is not permitted
    at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:293)
    at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2396)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2072)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2033)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1291)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

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" 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>Agro</display-name>
  <servlet>
   <display-name>AdminValidate</display-name>
   <servlet-name>AdminValidate</servlet-name>
   <servlet-class>com.kunal.servlet.AdminValidate</servlet-class>
  </servlet>
  <servlet-mapping>
   <servlet-name>AdminValidate</servlet-name>
   <url-pattern>/AdminValidate</url-pattern>
  </servlet-mapping>
  <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>
</web-app>

I tried all the solution on stackoverflow but nothing seems to help...if there is any other solution to this problem please post here.


Solution

  • Comments have provided the answers, still i would like to post as an answer

    Caused by: java.lang.IllegalArgumentException: The servlets named [AdminValidate] and [com.kunal.servlet.AdminValidate] are both mapped to the url-pattern [/AdminValidate] which is not permitted

    How would you expect the container to choose one servlet for an URL, when you have provided more than one servlet for the same URL pattern?

    Please check the web.xml for more than one servlet mapped to the same URL pattern.

    Think.