java.lang.IllegalArgumentException:Servlet映射指定未知的servlet名称

时间:2015-12-30 06:23:47

标签: tomcat servlets illegalargumentexception servlet-mapping

当我尝试运行我的项目时,我收到错误

Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name dispatcher
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3156)
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3135)
    at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1372)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1176)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
    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:5154)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

我的web.xml

<servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>dispatcher</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

2 个答案:

答案 0 :(得分:10)

<servlet-name>条目的<servlet-mapping>必须与<servlet-name>条目的<servlet>完全相同。

因此,在您的具体情况下,请在<servlet-mapping>条目

中更改此行
<servlet-name>dispatcher</servlet-name>

<servlet-name>DispatcherServlet</servlet-name>

答案 1 :(得分:0)

所述
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name dispatcher

<servlet><servlet-mapping>中的servlet名称必须相同。