二月 14, 2018 2:00:20 下午 org.springframework.web.servlet.PageNotFoundnoHandlerFound 警告: No mapping fou

xiaoxiao2021-02-28  33

问题:

  通过修改springmvc的配置后发现图片,js都无法映射,这就是典型的spring与静态资源处理冲突问题。

报错形式

二月 14, 2018 2:00:20 下午 org.springframework.web.servlet.PageNotFoundnoHandlerFound

警告: No mapping found for HTTP request with URI[/laboratory/static/image/background2.jpg] in DispatcherServlet with name'dispatcherServlet' 

是所以的资源请求都被spring默认处理了,如js文件,图片文件等,

解决方案:

1. 在springmvc的配置文件中添加一句默认处理

<!-- 将Springmvc不能处理的请求交给tomcat 这东西在该项目中是为了将spring无法处理的.js 图片文件等交给tomcat处理,也可以自己设置强制让spring处理-->

        <mvc:default-servlet-handler/>

 

2. 在springmvc的配置文件中添加mvc标签,要求springmvc管理映射请求的静态资源

      <mvc:resources mapping="/resources/**" location="/static/resources/" />

        <mvc:resources mapping="/images/**" location="/static/images/" />

        <mvc:resources mapping="/js/**"  location="/static/js/"/>

 

说明:location 是webapp根目录下的映射,请根据自己的目录的资源文件修改location

但是我进行页面跳转请求时,会出现404错误,或者图片显示不全。

解决办法:在下面加一句<mvc:annotation-driven/>

 

转载请注明原文地址: https://www.6miu.com/read-2627734.html

最新回复(0)