Spring:未找到带有 URI 的 HTTP 请求的映射
我已经开始使用 spring 并遇到此错误
No mapping found for HTTP request with URI [/SpringSocialSample/login.htm] in DispatcherServlet with name 'SpringSocialSample'
我认为调度程序 servlet My SpringSocialSample-servlet 无法找到 login.htm
。 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。
I have started using spring and am encountering this error
No mapping found for HTTP request with URI [/SpringSocialSample/login.htm] in DispatcherServlet with name 'SpringSocialSample'
I figured that login.htm cant be located by dispatcher servlet
My 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>
I have index.jsp where I redirect to login.jsp placed under WEB-INF/views..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将 Spring Dispatcher 映射到 *.htm,因此每次请求与该模式匹配的 url 时,调度程序都会查找映射到该特定 URL 请求的控制器,它不会尝试加载静态文件(也称为您的登录名) .html html 文件被此配置有效隐藏,除非您首先通过 Spring 控制器将其作为视图发送回来,否则您无法返回它。您创建一个返回该页面的 Spring 控制器,将其映射到 [login.htm] URI,然后 Spring 将不再抱怨它找不到该 URL 的映射:
查看章节“13.4. 处理程序映射”:
http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html
You've mapped the Spring Dispatcher to *.htm, so each time a url matching that pattern is requested, the dispatcher will look for a controller mapped to that specific URL request, it will NOT try to load static files (aka, your login.html html file is effectivelly hidden by this config, you cannot return it unless you first pass through a Spring Controller that sends it back as a view). You create a Spring Controller that returns that page, map it to the [login.htm] URI, and then Spring will no longer complain that it cannot find a mapping for that URL:
Check out the chapter "13.4. Handler mappings" from :
http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html