Tomcat 7:无效映射(java.lang.IllegalArgumentException)

时间:2013-07-02 12:51:23

标签: java tomcat servlets tomcat7 web.xml

我正在将现有项目从Tomcat 6迁移到7.启动后,我遇到此错误消息:

Jul 02, 2013 2:38:39 PM org.apache.catalina.startup.ContextConfig parseWebXml
SEVERE: Parse error in application web.xml file at jndi:/localhost/padd/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/padd/WEB-INF/web.xml; lineNumber: 309; columnNumber: 21; Error at (309, 21) : The servlets named [ArtefactServlet] and [saveArtefactServlet] are both mapped to the url-pattern [/saveRestoration] which is not permitted
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
    ...
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: The servlets named [ArtefactServlet] and [saveArtefactServlet] are both mapped to the url-pattern [/saveRestoration] which is not permitted

这里的 WEB-INF / web.xml 行309fff:

  <servlet-mapping>
    <servlet-name>saveArtefactServlet</servlet-name>
    <url-pattern>/saveRestoration</url-pattern>
  </servlet-mapping>

编辑:

  <servlet-mapping>
    <servlet-name>ArtefactServlet</servlet-name>
    <url-pattern>/saveRestoration</url-pattern>
  </servlet-mapping>

此处 tomcat的web.xml

<servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <!-- The mappings for the JSP servlet -->
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>

我尝试使用映射,但无法取得任何进展。希望你能帮忙!

2 个答案:

答案 0 :(得分:4)

错误说:

  

名为[ArtefactServlet]和[saveArtefactServlet]的servlet是   两者都映射到url-pattern [/ saveRestoration],而不是   允许

因此,当您的url模式匹配时,tomcat不知道要调用哪个servlet。为这两个servlet提供不同的url模式 ArtefactServlet saveArtefactServlet

答案 1 :(得分:0)

return

我找到了这个原因,我在不同的包中创建了新的servlet(name ='syncro')。我的servlet位于 syncro.SynchronizeServlet 中 当我在部署描述符(web.xml)中添加有关此servlet的信息时,我发现错误: IllegalArgumentException

描述符部分不正确的示例:

java.lang.IllegalArgumentException: The servlets named...

当我为servlet添加正确的路径时 - 错误消失了。正确的desc如下:

<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>

==&GT; 73!