1

我已經創建了一個Eclipse動態Web項目在本文檔中提及的網址模式:sampledoc拋出:IllegalArgumentException:你好]命名的servlet和[com.crunchify.jsp.servlet.HelloCrunchify]都映射到

當我在服務器上運行的程序,我得到這個錯誤在控制檯:

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家被設定爲 「javac 1.8.0_05」 。 請幫忙!!!

+0

這很奇怪,它說'/ CrunchifyServlet'被映射了兩次,但我只能在web.xml中看到1! – Yazan

回答

1

我認爲堆棧跟蹤的關鍵部分是這樣的:

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

你要麼需要刪除這些servlet的一個或解除衝突的網址模式。你有另一個應用程序映射到相同的網址模式?

+0

感謝您的回答。我編輯了我的網址模式,它工作。 – Sweet

1

您省略了一些相關信息,您的其他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。 試着改變的URI/CrunchifyServlet只/ 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> 
+0

感謝您的回答。我編輯了我的網址模式,它工作。 – Sweet

-1

試試這個:

轉到

C:\ Program Files文件\ Apache軟件基金會\ Apache Tomcat上8.x.xx \ BIN

找到

catalina.bat

將其複製並粘貼到另一個驅動器中,因爲Windows不會讓您在此編輯。 現在用任何編輯器打開文件。

查找noJuliConfig和noJuliManager,你將到達的地方像這樣的圖像 Before Editing

你可以清楚地看到noJuliConfig和noJuliManager一個set JAVA_OTPS="Something"

現在你要做的是去掉雙引號,一個編輯的部分看起來像這樣After Editing

現在只需更換原有catalina.bat中與此編輯之一。 重新啓動您的IDE。 你完成了。

您可以稍後爲此感謝我。 :D

+0

我沒有嘗試過,因爲它通過編輯Boo和pczeus提到的URL模式來工作。 – Sweet

相關問題