Spring Mvc返回html页面404错误解决记录--转载
原文地址:http://53873039oycg.iteye.com/blog/2061992
以前使用Spring Mvc时候都是返回jsp页面或者ftl页面,昨天想返回html页面,spring-mvc.xml配置如下:
- <bean id="viewResolver"
- class="org.springframework.web.servlet.view.InternalResourceViewResolver"
- p:prefix="/WEB-INF/html/" p:suffix=".html" />
Controller方法如下:
- @RequestMapping(value = "/add", method = RequestMethod.GET)
- public String toAddTest() {
- return "addTest";
- }
在tomcat下测试,页面一直是404,log日志如下:
- [06/05/14 10:44:35:035 GMT+08:00] DEBUG support.DefaultListableBeanFactory: Returning cached instance of singleton bean 'sqlSessionFactory'
- [06/05/14 10:44:35:035 GMT+08:00] DEBUG servlet.DispatcherServlet: Successfully completed request
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG servlet.DispatcherServlet: DispatcherServlet with name 'spring' processing GET request for [/MyTest/test/add]
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG annotation.RequestMappingHandlerMapping: Looking up handler method for path /test/add
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG annotation.RequestMappingHandlerMapping: Returning handler method [public java.lang.String com.report.controller.testController.toaddTest()]
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG support.DefaultListableBeanFactory: Returning cached instance of singleton bean 'testController'
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG servlet.DispatcherServlet: Last-Modified value for [/MyTest/test/add] is: -1
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG servlet.DispatcherServlet: Rendering view [org.springframework.web.servlet.view.JstlView: name 'addTest'; URL [/WEB-INF/html/addTest.html]] in DispatcherServlet with name 'spring'
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG view.JstlView: Forwarding to resource [/WEB-INF/html/addTest.html] in InternalResourceView 'addTest'
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG servlet.DispatcherServlet: DispatcherServlet with name 'spring' processing GET request for [/MyTest/WEB-INF/html/addTest.html]
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG annotation.RequestMappingHandlerMapping: Looking up handler method for path /WEB-INF/html/addTest.html
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG annotation.RequestMappingHandlerMapping: Did not find handler method for [/WEB-INF/html/addTest.html]
- [06/05/14 10:44:38:038 GMT+08:00] WARN servlet.PageNotFound: No mapping found for HTTP request with URI [/MyTest/WEB-INF/html/addTest.html] in DispatcherServlet with name 'spring'
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG servlet.DispatcherServlet: Successfully completed request
- [06/05/14 10:44:38:038 GMT+08:00] DEBUG servlet.DispatcherServlet: Successfully completed request
可以看出No mapping found for HTTP request with URI错误导致了404,问题原因:
参考了http://stackoverflow.com/questions/13616821/make-html-default-view-spring-mvc
2 The DispatcherServlet finds a mapping which maps to the home method of your Controller and the home method returns a view name "HelloWorld"
3 Now the DispatcherServlet uses a View Resolver (your InternalResourceViewResolver) to find the View to render the model through, since the name is "HelloWorld", this maps to the /WEB-INF/view/HelloWorld.html view.
4 Now essentially a call is made to RequestDispatcher.forward("/WEB-INF/views/HelloWorld.html",....
5 The Servlet container at this point tries to find the servlet which can handle /WEB-INF/views/HellowWorld.html uri - if it had been a .jsp there is a JSPServlet registered which can handle rendering the jsp, however for *.html there is no servlet registered, so the call ends up with the "default servlet", which is registered with a servlet-mapping of / which probably your DispatcherServlet is.
6 Now the Dispatcher servlet does not find a controller to handle request for /WEB-INF/views/HelloWorld.html and hence the message that you are seeing
解决方法:
http://stackoverflow.com/questions/4249622/using-html-files-as-jsps
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
再次访问就OK了。
全文完。
Spring Mvc返回html页面404错误解决记录--转载的更多相关文章
- spring mvc访问html页面404报错解决
<servlet> <servlet-name>context</servlet-name> <servlet-class>org.springfram ...
- spring mvc MultipartFile 上传文件错误解决
Field error in object 'xxxx' on field 'xxxx': rejected value [20129259128131.jpg]; codes [typeMismat ...
- Spring MVC与html页面的交互(以传递json数据为例)
一.导入相jar包 主要包括spring相关jar包和fastjson jar包,具体步骤略. 二.配置相关文件 1.配置web.xml文件 <?xml version="1.0&qu ...
- 转:spring mvc model.addAttribute页面c:forEach取不到
原文链接:http://www.cnblogs.com/beautifulFuture/p/3957426.html spring mvc model.addAttribute页面c:forEach取 ...
- spring mvc返回json字符串的方式
spring mvc返回json字符串的方式 方案一:使用@ResponseBody 注解返回响应体 直接将返回值序列化json 优点:不需要自己再处理 步骤一:在spring- ...
- spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable
1.spring mvc返回json数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable 2. @RequestMapping(val ...
- IIS7或者IIS7.5部署MVC项目时出现404错误
IIS7或者IIS7.5部署MVC项目时出现404错误 服务器上需要安装Windows 补丁 kb980368 下载链接:http://support.microsoft.com/kb/980368
- Spring MVC 返回NULL时客户端用$.getJSON的问题
如果Spring MVC返回是NULL,那么客户端的$.getJSON就不会触发: 必须返回点什么东西: 如果返回的是一个字符串,客户端的$.getJSON也不会触发:把字符串 包装成List< ...
- http协议 put、delete请求asp.net mvc应用,报404错误
http协议 put.delete请求asp.net mvc应用,报404错误 更改web.config,在<modules>节点中设置 runAllManagedModulesForAl ...
随机推荐
- Spark RDD概念学习系列之RDD的缓存(八)
RDD的缓存 RDD的缓存和RDD的checkpoint的区别 缓存是在计算结束后,直接将计算结果通过用户定义的存储级别(存储级别定义了缓存存储的介质,现在支持内存.本地文件系统和Tachyon) ...
- Sharding & IDs at Instagram(转)
英文原文:http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram 译文:http://ww ...
- cocos2d-x使用python创建vs模板
cocos2d-x 2.2推荐使用create_project.py创建工程,所有的平台都可以通过这个python文件创建工程.这个文件位置在源码cocos2d-x-2.2.2\tools\proje ...
- 深入剖析AutoreleasePool
[深入剖析AutoreleasePool] Objc的AutoreleasePool是一个首尾相连的内存链接,每块大小为1页(32位机上为4kb). 上面可以看到,parent指向父Pool,chil ...
- GLSL Notes
[GLSL Notes] API of shader: glCreateShader(), glShaderSource(), glCompileShader(), glGetShadrInfoLog ...
- cvc-elt.1: Cannot find the declaration of element 'beans'
@(编程) 现象描述 导入的一个eclipse项目报错,各种方法都无法解决,报错信息如下: cvc-elt.1: Cannot find the declaration of element 'bea ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- JavaScript学习——内置属性
在js中,几乎所有的对象都是同源对象,都继承Object对象.对象的内置属性指的是它们作为Object实例所具有的属性,这些属性通常反映对象本身的基本信息和数据无关.因此我们称它们为元属性.这些属性通 ...
- 关于Unity
14年左右的时候开始学习了Unity,一直没有时间总结一些东西,框架机制啥的都不用说了,网上到处都有,虽然Unity是脚本机制,但是熟悉编程的人只要理解透了拿面向对象的思维编码也完全没有问题,这里重新 ...
- UVa 10316 - Airline Hub
题目:给出地球上的n个机场的经度和纬度,想在这里面确定一个HUB使得他到其他机场的最大距离最小. 分析:计算几何.大地坐标系.因为数据不大直接枚举即可,比较时利用圆心角可以提高计算效率,并控制精度. ...