Spring MVC:“在名为“dispatcher”的 DispatcherServlet 中没有 [...] 映射”
有人可以帮助我吗?在 Spring MVC 中,我收到错误
- 警告:没有 [/TechBooks/details.htm] 的映射 名称为“dispatcher”的 DispatcherServlet
1) 首先,在 web.xml 中,我使用标准的 DispatcherServlet 来拦截所有 *.htm,这里没有什么不寻常的,这是预先编写的我:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
2)在dispatcher-servlet.xml中,我使用SimpleUrlHandlerMapping,这也是标准的和预先编写的:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
3)也在dispatcher-servlet.xml,我定义了名为“DetailsFormController”的 FormController 类,它映射到 details.htm:
<bean name="/details.htm" class="techbooks.web.DetailsFormController"/>
4)DetailsFormController 类是表单的 FormController。
package techbooks.web;
public class DetailsFormController extends SimpleFormController {
....
}
但是,当我执行资源 /details.htm 时,出现上述错误。
- 警告:[/TechBooks/details.htm] 中没有映射 名称为“dispatcher”的 DispatcherServlet
任何想法将不胜感激。谢谢。
Can someone help me. In Spring MVC I'm getting the error
- WARNING: No mapping for [/TechBooks/details.htm] in
DispatcherServlet with name 'dispatcher'
1) First of all, in web.xml, I use the standard DispatcherServlet which intercepts all *.htm, nothing unusual here, this was pre-written for me:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
2) In dispatcher-servlet.xml, I am using the SimpleUrlHandlerMapping, again this is standard and pre-written:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
3) Also in dispatcher-servlet.xml, I define my FormController class called "DetailsFormController", that maps to details.htm:
<bean name="/details.htm" class="techbooks.web.DetailsFormController"/>
4) And the class DetailsFormController is a FormController for a form.
package techbooks.web;
public class DetailsFormController extends SimpleFormController {
....
}
When I execute the resource /details.htm, however, I get the above error.
- WARNING: No mapping for [/TechBooks/details.htm] in
DispatcherServlet with name 'dispatcher'
Any ideas would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 bean 定义更改为
或为 TechBooks 编写一个 urlmapping 处理程序吗
Can you change your bean difinition to
Or write a urlmapping handler for TechBooks
我发现问题是什么了。
使用 SimpleUrlHandlerMapping 时,控制器名称必须是 DetailsController,而不是 DetailsFormController,因此它会自动映射到正确的 JSP。
I found out what the issue was.
When using the SimpleUrlHandlerMapping, the Controller name has to be DetailsController, not DetailsFormController, so it maps automatically to the right JSP.