mvc:resources 配置不起作用

springmvc配置静态文件不起作用:

clipboard.png

SpringMCV:
<mvc:resources mapping="/css/**" location="/resources/css/" />

页面:
<head>

<title>Title</title>
<link rel="stylesheet"   href="resources/css/yapyan.css" />

浏览器控制台报如下错误:

Resource interpreted as Stylesheet but transferred with MIME type text/html: 
"http://localhost:8080/resources/css/yapyan.css".    
阅读 7.2k
2 个回答

错误原因为:Resource interpreted as Stylesheet but transferred with MIME type text/html
这是因为你请求 yapyan.css 文件时服务器的 Content-Type 内容为 text/html ,正确的应该是 text/css
试一下访问 js 文件,看看他的 Content-Type 是不是 application/javascript
你路径配置是 <mvc:resources mapping="/css/**" location="/resources/css/" />
那么请求 url 地址应该是 <link rel="stylesheet" type="text/css" href="/css/yapyan.css" />

配置里加上这句试试 <mvc:default-servlet-handler/>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题