No mapping found for HTTP request with URI [/superMarket/css/style.css] in DispatcherServlet with na

在测试写的前端代码的时候遇到问题
[org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/superMarket/css/style.css] in DispatcherServlet with name ‘SpringMVC’
No mapping found for HTTP request with URI [/superMarket/css/style.css] in DispatcherServlet with na_第1张图片
页面出现以上内容。
罪魁祸首是web.xml下对spring的DispatcherServlet请求url映射的配置,原配置如下:
No mapping found for HTTP request with URI [/superMarket/css/style.css] in DispatcherServlet with na_第2张图片
分析原因:的/把所有的请求都交给spring去处理了,而所有available的请求url都是在Constroller里使用类似@RequestMapping(value = “/login/{user}”, method = RequestMethod.GET)这样的注解配置的,这样的话对js/css/jpg/gif等静态资源的访问就会得不到。
解决方法:
在xml中加入:

<servlet-mapping>
     <servlet-name>defaultservlet-name>
     <url-pattern>*.cssurl-pattern>
servlet-mapping>

<servlet-mapping>
    <servlet-name>defaultservlet-name>
    <url-pattern>*.gifurl-pattern>

 servlet-mapping>

 <servlet-mapping>
     <servlet-name>defaultservlet-name>
     <url-pattern>*.jpgurl-pattern>
 servlet-mapping>

 <servlet-mapping>
     <servlet-name>defaultservlet-name>
     <url-pattern>*.jsurl-pattern>
 servlet-mapping>

解决!

你可能感兴趣的:(SSM)