我已经开始使用spring并遇到此错误
在DispatcherServlet中找不到名为“SpringSocialSample”的带有URI [/SpringSocialSample/login.htm]的HTTP请求的映射
我认为login.htm无法通过调度程序servlet找到
我的SpringSocialSample-servlet.xml
<context:component-scan
base-package="com.social.spring.controllers" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".jsp" />
的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_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>SpringSocialSample</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>updatestatus.root</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>SpringSocialSample</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringSocialSample</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我有index.jsp,我重定向到位于WEB-INF / views下的login.jsp ..
答案 0 :(得分:2)
您已将Spring Dispatcher映射到* .htm,因此每次请求匹配该模式的url时,调度程序将查找映射到该特定URL请求的控制器,它不会尝试加载静态文件(aka ,您的login.html html文件被此配置有效隐藏,除非您首先通过将其作为视图发回的Spring Controller,否则无法返回它。您创建一个返回该页面的Spring Controller,将其映射到[login.htm] URI,然后Spring将不再抱怨它无法找到该URL的映射:
查看以下章节“13.4。处理程序映射”:
http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html