spring的MVC问题

fir01 发布于 2014/02/22 12:28
阅读 3K+
收藏 1

环境:spring3.1.1

问题:起源于配置spring mvc多个视图,配置dispatcherServlet路径为/*的时候默认匹配mapping所有路径,配置为/时,匹配所有的不带.后缀的路径。

测试一:配置/*路径,不能访问到多视图的jsp

DispatcherServlet with name 'dispatcherServlet' processing GET request for [/online/jsp/img.jsp]
Looking up handler method for path /jsp/img.jsp
Returning handler method [public org.springframework.web.servlet.ModelAndView com.anyvape.admin.controller.ViewsController.viewJsp(java.lang.String,org.springframework.ui.Model)]
Last-Modified value for [/online/jsp/img.jsp] is: -1
Rendering view [org.springframework.web.servlet.view.JstlView: name 'img'; URL [/jspx/img.jsp]] in DispatcherServlet with name 'dispatcherServlet' 这里渲染了

Added model object 'templateSign' of type [java.lang.String] to request in view with name 'img'

Forwarding to resource [/jspx/img.jsp] in InternalResourceView 'img' 这里为什么又Forwarding ?导致404错误。

DispatcherServlet with name 'dispatcherServlet' processing GET request for [/online/jspx/img.jsp]
Looking up handler method for path /jspx/img.jsp
Did not find handler method for [/jspx/img.jsp]
No mapping found for HTTP request with URI [/online/jspx/img.jsp] in DispatcherServlet with name 'dispatcherServlet'

测试二:使用/配置路径,直接访问到jsp,不经springDispatcherServlet ;


所以最后配置多视图,只能配置/,然后再集合viewName内含有固定字符去匹配不同视图。例如访问文件/jspx/img.jsp的路径使用/jspx/img访问,内部配置controller路径匹配/jspx/img,返回view的view拼字符串jsp,这样就能正常了

加载中
返回顶部
顶部