當前位置:
首頁 >
Spring Mvc返回html页面404错误解决记录--转载
發(fā)布時間:2025/4/5
46
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Spring Mvc返回html页面404错误解决记录--转载
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
原文地址:http://53873039oycg.iteye.com/blog/2061992
?以前使用Spring Mvc時候都是返回jsp頁面或者ftl頁面,昨天想返回html頁面,spring-mvc.xml配置如下:
?
Xml代碼??????Controller方法如下:
??
Java代碼??????在tomcat下測試,頁面一直是404,log日志如下:
?
Java代碼???
???可以看出No mapping found for HTTP request with URI錯誤導致了404,問題原因:
?
?? 參考了http://stackoverflow.com/questions/13616821/make-html-default-view-spring-mvc
?
?
寫道 1 First the DispatcherServlet is invoked by the Servlet Container.?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
???
寫道 Add this servletmapping for the JSP servlet(web.xml):?<servlet-mapping>?
<servlet-name>jsp</servlet-name>?
<url-pattern>*.html</url-pattern>?
</servlet-mapping>
???再次訪問就OK了。
?
?? 全文完。
轉載于:https://www.cnblogs.com/davidwang456/p/4500384.html
總結
以上是生活随笔為你收集整理的Spring Mvc返回html页面404错误解决记录--转载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tomcat7启动报Error list
- 下一篇: Spring3中js/css/jpg/g