2

I have created a dynamic web project in eclipse as mentioned in this doc: sampledoc

When I run the program in server, I get this error in the console:

Caused by: java.lang.IllegalArgumentException: The servlets named [Hello] and [com.crunchify.jsp.servlet.HelloCrunchify] are both mapped to the url-pattern [/CrunchifyServlet] which is not permitted
    at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:308)
    at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2373)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2055)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1940)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1934)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1934)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1934)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1934)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1147)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:779)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:306)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5150)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 6 more

I tried deleting the server from the Servers tab and adding again. Did a project clean. Nothing seems to solve the problem.

My web.xml looks like this:

<?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"
version="3.0">
<display-name>CrunchifyJSPServletExample</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>Hello</servlet-name>
    <servlet-class>com.crunchify.jsp.servlet.HelloCrunchify</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/CrunchifyServlet</url-pattern>
</servlet-mapping>

I am using Tomcat 8 and my java home is set to "javac 1.8.0_05" . Please help!!!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sweet
  • 187
  • 3
  • 15
  • that's strange, it says `/CrunchifyServlet` is mapped twice but i can see only 1 at web.xml! – Yazan Apr 03 '16 at 20:15

3 Answers3

1

You have omitted some relevant information, your other servlet mappings. The error tells it all:

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

You have two servlet mappings, mapped to the same URI. Try changing the URI for the /CrunchifyServlet to just /Crunchify

<servlet>
    <servlet-name>Hello</servlet-name>
    <servlet-class>com.crunchify.jsp.servlet.HelloCrunchify</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/Crunchify</url-pattern>
</servlet-mapping>
pczeus
  • 7,709
  • 4
  • 36
  • 51
1

I think the key part of that stack trace is this:

The servlets named [Hello] and [com.crunchify.jsp.servlet.HelloCrunchify] are both mapped to the url-pattern [/CrunchifyServlet] which is not permitted

You will either need to remove one of these servlets or deconflict the url-patterns. Do you have another application that is mapped to the same url-pattern?

Boo Radley
  • 684
  • 1
  • 13
  • 25
-1

Try This one :

Go to

C:\Program Files\Apache Software Foundation\Apache Tomcat 8.x.xx\bin

find

catalina.bat

copy and paste it into another drive as windows will not let you edit here. Now open the file with any editor.

Find noJuliConfig and noJuliManager, you will reach somewhere like this image Before Editing

You can clearly see one set JAVA_OTPS="Something"for noJuliConfig and noJuliManager.

Now all you have to do is to remove the double quotes, an the edited part will look like thisAfter Editing

Now just replace the original catalina.bat with this edited one. Restart your IDE. and you're done.

You can thank me later for that. :D

Arpit Porwal
  • 273
  • 3
  • 14
  • I did not try this, since it worked by editing the URL-pattern as mentioned by Boo and pczeus. – Sweet Apr 03 '16 at 21:43