【问题标题】:IllegalArgumentException: The servlets named [Hello] and [com.crunchify.jsp.servlet.HelloCrunchify] are both mapped to the url-pattern [duplicate]IllegalArgumentException:名为 [Hello] 和 [com.crunchify.jsp.servlet.HelloCrunchify] 的 servlet 都映射到 url 模式 [重复]
【发布时间】:2016-07-23 06:41:41
【问题描述】:

我在 Eclipse 中创建了一个动态 Web 项目,如本文档所述:sampledoc

当我在服务器中运行程序时,我在控制台中收到此错误:

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

我尝试从“服务器”选项卡中删除服务器并再次添加。做了一个项目清理。似乎没有什么能解决问题。

我的 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"
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>

我使用的是 Tomcat 8,我的 java home 设置为“javac 1.8.0_05” . 请帮忙!!!

【问题讨论】:

  • 这很奇怪,它说/CrunchifyServlet 被映射了两次,但我在 web.xml 中只能看到 1 个!

标签: eclipse tomcat servlets illegalargumentexception servlet-mapping


【解决方案1】:

我认为堆栈跟踪的关键部分是:

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

您要么需要删除其中一个 servlet,要么消除 url 模式的冲突。您是否有另一个应用程序映射到相同的 url-pattern?

【讨论】:

  • 感谢您的回答。我编辑了我的 url-pattern,它起作用了。
【解决方案2】:

您省略了一些相关信息,您的其他 servlet 映射。 错误说明了一切:

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

您有两个 servlet 映射,映射到同一个 URI。 尝试将 /CrunchifyServlet 的 URI 更改为 /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>

【讨论】:

  • 感谢您的回答。我编辑了我的 url-pattern,它起作用了。
【解决方案3】:

试试这个:

前往

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

找到

catalina.bat

将其复制并粘贴到另一个驱动器中,因为 Windows 不允许您在此处进行编辑。 现在用任何编辑器打开文件。

找到 noJuliConfig 和 noJuliManager,你会到达类似这张图片的地方 Before Editing

您可以清楚地看到一个set JAVA_OTPS="Something"for noJuliConfig 和 noJuliManager。

现在你要做的就是删除双引号,编辑后的部分将如下所示After Editing

现在只需将原来的 catalina.bat 替换为经过编辑的文件即可。 重新启动您的 IDE。 你就完成了。

你可以稍后感谢我。 :D

【讨论】:

  • 我没有尝试这个,因为它是通过编辑 Boo 和 pczeus 提到的 URL 模式来工作的。
猜你喜欢
  • 2013-09-19
  • 2013-07-27
  • 2014-10-06
  • 2016-11-26
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 2013-12-13
  • 2016-03-07
相关资源
最近更新 更多