Spring Mvc 配置web.xml中的servlet-mapping时遇到的问题

来源:互联网 发布:手机阿里云os登录 编辑:程序博客网 时间:2024/06/06 11:40

今天在优化一个项目,因为是优化所以会有很多对原有代码的调整。对Spring mvc配置的路径进行了配置如下:

修改前

    <servlet-mapping>        <servlet-name>appServlet</servlet-name>        <url-pattern>/smart/*</url-pattern>    </servlet-mapping>

修改后

    <servlet-mapping>        <servlet-name>appServlet</servlet-name>        <url-pattern>/*</url-pattern>    </servlet-mapping>

因为疏忽和对spring mvc拦截机制的了解不够彻底导致无法获得无法返回视图,控制台输出如下log日志。

2016-12-11 17:12:11|DEBUG| [DefaultListableBeanFactory-->invokeInitMethods] --- Invoking afterPropertiesSet() on bean with name 'WEB-INF/views/login.jsp'2016-12-11 17:12:11|DEBUG| [DispatcherServlet-->render] --- Rendering view [org.springframework.web.servlet.view.JstlView: name 'WEB-INF/views/login.jsp'; URL [/WEB-INF/views/login.jsp]] in DispatcherServlet with name 'appServlet'2016-12-11 17:12:11|DEBUG| [JstlView-->renderMergedOutputModel] --- Forwarding to resource [/WEB-INF/views/login.jsp] in InternalResourceView 'WEB-INF/views/login.jsp'2016-12-11 17:12:11|DEBUG| [DispatcherServlet-->doService] --- DispatcherServlet with name 'appServlet' processing GET request for [/saa/WEB-INF/views/login.jsp]2016-12-11 17:12:11|DEBUG| [RequestMappingHandlerMapping-->getHandlerInternal] --- Looking up handler method for path /WEB-INF/views/login.jsp2016-12-11 17:12:11|DEBUG| [RequestMappingHandlerMapping-->getHandlerInternal] --- Did not find handler method for [/saa/WEB-INF/views/login.jsp]2016-12-11 17:12:11|WARN | [PageNotFound-->noHandlerFound] --- No mapping found for HTTP request with URI [/saa/WEB-INF/views/login.jsp] in DispatcherServlet with name 'appServlet'2016-12-11 17:12:11|DEBUG| [DispatcherServlet-->doService] --- DispatcherServlet with name 'appServlet' processing GET request for [/saa/404.html]2016-12-11 17:12:11|DEBUG| [RequestMappingHandlerMapping-->getHandlerInternal] --- Looking up handler method for path /404.html2016-12-11 17:12:11|DEBUG| [RequestMappingHandlerMapping-->getHandlerInternal] --- Did not find handler method for [/404.html]2016-12-11 17:12:11|WARN | [PageNotFound-->noHandlerFound] --- No mapping found for HTTP request with URI [/saa/404.html] in DispatcherServlet with name 'appServlet'2016-12-11 17:12:11|DEBUG| [DispatcherServlet-->processRequest] --- Successfully completed request2016-12-11 17:12:11|DEBUG| [DefaultListableBeanFactory-->doGetBean] --- Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'2016-12-11 17:12:11|DEBUG| [DispatcherServlet-->processRequest] --- Successfully completed request2016-12-11 17:12:11|DEBUG| [DispatcherServlet-->processRequest] --- Successfully completed request2016-12-11 17:12:11|DEBUG| [OpenSessionInViewFilter-->doFilterInternal] --- Closing Hibernate Session in OpenSessionInViewFilter

经过多日志分析发现,输出的日志中有视图渲染的操作

[DispatcherServlet-->render] --- Rendering view [org.springframework.web.servlet.view.JstlView: name 'WEB-INF/views/login.jsp'; URL [/WEB-INF/views/login.jsp]] in DispatcherServlet with name 'appServlet'[JstlView-->renderMergedOutputModel] --- Forwarding to resource [/WEB-INF/views/login.jsp] in InternalResourceView 'WEB-INF/views/login.jsp'

在渲染后的spring mvc会输出成功或者找到视图,在看下面的日志后发现spring mvc又拦截了自己渲染视图的forward的操作,正常的渲染视图操作被解析为forwod后就会把视图的url当做请求的url,在第二次请求时因为没有找到对应Controller导致抛出404错误。

[DispatcherServlet-->doService] --- DispatcherServlet with name 'appServlet' processing GET request for [/saa/WEB-INF/views/login.jsp][RequestMappingHandlerMapping-->getHandlerInternal] --- Looking up handler method for path /WEB-INF/views/login.jsp[RequestMappingHandlerMapping-->getHandlerInternal] --- Did not find handler method for [/saa/WEB-INF/views/login.jsp][PageNotFound-->noHandlerFound] --- No mapping found for HTTP request with URI [/saa/WEB-INF/views/login.jsp] in DispatcherServlet with name 'appServlet'[DispatcherServlet-->doService] --- DispatcherServlet with name 'appServlet'
0 0
原创粉丝点击