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

后端 未结 6 2001
深忆病人
深忆病人 2020-11-22 05:21

I tried to add this servlet

package com.classmgt.servlet;

@WebServlet(\"/ControllerServlet\")
public class ControllerServlet extends HttpServlet {}
         


        
相关标签:
6条回答
  • 2020-11-22 05:40

    The servlets named [Register] and [com.TeamWork.controller.Register] are both mapped to the url-pattern [/Register] which is not permitted

    getting this error you have to remove your servlet mapping from web.xml and just add @WebServlet("/Register") annotation + url

    <servlet>
         <servlet-name>Register</servlet-name>
         <servlet-class>com.TeamWork.controller</servlet-class>
      </servlet>
    

    then your servlet class on the top add this one

    @WebServlet("/Register")`
    public class Register extends HttpServlet { }
    

    it will work thanks

    0 讨论(0)
  • 2020-11-22 05:42

    What worked for me is doing a 'clean'.

    My issue was caused when the Servlet class was renamed. However, the original .class files remained in the target directory (with their Servlet annotation). It looks like you moved your ControllerServlet into a package.

    Jetty didn't seem to mind these apparent duplicates, but Tomcat7 gave your 'both mapped to the url-pattern' exception.

    The easy way to see if this is causing your issue is to look in the WAR to see if both the old classes (in your case [ControllerServlet] and [com.classmgt.servlet.ControllerServlet]) are both there.

    0 讨论(0)
  • 2020-11-22 05:45

    As for me I added the tom-cat version to my pom file and it worked

    <properties>
        <tomcat.version>7.0.52</tomcat.version>
    </properties>
    <dependencies>
    
    0 讨论(0)
  • 2020-11-22 05:46

    Just remove the annotation @WebServlet("/ControllerServlet"), from the ControllerServlet, because it already added in the web.xml.

    0 讨论(0)
  • 2020-11-22 05:56

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

    It seems that you have mixed @WebServlet annotation based and web.xml based configuration.

    I doubt that you created a Servlet using the "Create Servlet" wizard which creates web.xml entry with url-pattern and then , added a @WebServlet annotation which duplicates anything you may put in the web.xml.

    You should use the one or the other, not both. Remove the mapping from web.xml and go ahead with using only the @WebServlet annotation.

    Read more: Servlet 3.0 Annotations and our Servlets wiki page.

    0 讨论(0)
  • 2020-11-22 05:59
    java.lang.IllegalArgumentException: The servlets named...
    

    I fetched this cause where I create new servlet in different package (name='syncro'). My servlet located in syncro.SynchronizeServlet And when I add information about this servlet in deployment descriptor (web.xml) I catch error: IllegalArgumentException

    Example of incorrect descriptor part:

    <servlet>
        <description></description>
        <display-name>SynchronizeServlet</display-name>
        <servlet-name>SynchronizeServlet</servlet-name>
        <servlet-class>SynchronizeServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>SynchronizeServlet</servlet-name>
        <url-pattern>/SynchronizeServlet</url-pattern>
        <url-pattern>/SynServlet</url-pattern>
      </servlet-mapping>
    

    When I add correct path for servlet - error disappeared. Correct desc below:

    <servlet>
        <description></description>
        <display-name>syncro.SynchronizeServlet</display-name>
        <servlet-name>syncro.SynchronizeServlet</servlet-name>
        <servlet-class>syncro.SynchronizeServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>syncro.SynchronizeServlet</servlet-name>
        <url-pattern>/SynchronizeServlet</url-pattern>
        <url-pattern>/SynServlet</url-pattern>
      </servlet-mapping>
    

    ==> 73!

    0 讨论(0)
提交回复
热议问题