SpringMVC错误之No mapping found for HTTP request with [url]
来源:互联网 发布:2020年庚子大难知乎 编辑:程序博客网 时间:2024/06/11 04:28
- spring的配置如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <bean id="/productSave.action" class="Controller.ProductSaveController"></bean> <bean id="/productForm.action" class="Controller.ProductFormController"></bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property> </bean></beans>
其中配置了视图解析器viewResolver,ProductSaveController和ProductFormController两个实现了org.springframework.web.servlet.mvc.Controller接口的实现类根据不同的url返回不同的视图路径,ProductFormController的代码如下:
package Controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;public class ProductFormController implements Controller { public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { //这里只返回了一个视图对象 return new ModelAndView("productFrom"); }}
- web.xml的配置如下:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app> <display-name>Archetype Created Web Application</display-name> <!-- The front controller of this Spring Web application, responsible for handling all application requests --> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
- 错误原因:这里url-pattern拦截了所有请求,报错原因就在于当IOC容器注入一个bean时(比如id=”/productForm.action”的bean),该bean将返回一个view的路径,而 DispatcherServlet又将该view的路径当作另一个请求,再次对其进行拦截,而此时spring的配置文件中并没有对这个路径进行映射,因此报错。
- 解决方案:
- 更改拦截url,只拦截以.action结尾的请求:
<url-pattern>*.action</url-pattern>
- 在spring的配置文件中配置访问静态资源的servlet:
<mvc:default-servlet-handler/>
- 更改拦截url,只拦截以.action结尾的请求:
阅读全文
0 0
- SpringMVC错误之No mapping found for HTTP request with [url]
- mark springmvc [No mapping found for HTTP request with URI]
- springMVC No mapping found for HTTP request with URI
- springMVC No mapping found for HTTP request with URI
- springMVC No mapping found for HTTP request with URI
- springMVC No mapping found for HTTP request with URI
- springMVC--关于no mapping found for http request with uri
- springMVC--关于no mapping found for http request with uri .......
- springMVC No mapping found for HTTP request with URI
- springMVC No mapping found for HTTP request with URI
- springmvc 出现No mapping found for HTTP request with URI
- springMVC报WARNING: No mapping found for HTTP request with URI [/springMVC/hello] in DispatcherServle
- 警告: No mapping found for HTTP request with URI [/Springmvc/test] in DispatcherServlet with dispatche
- No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springmvc'
- No mapping found for HTTP request with URI [/springmvc/queryitems.action] in DispatcherServlet with
- No mapping found for HTTP request with URI [/chart/get] in DispatcherServlet with name 'SpringMVC‘
- No mapping found for HTTP request with URI [/index.do] in DispatcherServlet with name 'SpringMVC‘
- SpringMVC:No mapping found for HTTP request with URI [/account/*] in DispatcherServlet with
- Temporary Post Used For Theme Detection (0ecb8fae-2539-45f9-a310-9e6b31cb889d
- ubuntu 修改root密码
- java文件写入
- 硬件支持openwrt系统第一步
- N皇后问题(DFS)
- SpringMVC错误之No mapping found for HTTP request with [url]
- 【绘图算法】Bresenham算法(草稿)
- Swift3.0基本语法02
- HTML阴影旋转移动
- echarts绘制地图随录
- get 与 post的区别?application json 与form表单的区别?
- 内网和外网的区别 连接不同设备上网
- 让人相见恨晚的vim插件:模糊查找神器LeaderF
- java本地文件与文件夹