<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,maximum-scale=1,minimum-scale=1,initial-scale=1,user-scalable=no,viewport-fit=cover">
<title>app</title>
<link href=./static/css/app.99a1cac4de029656ce1420df9f08e6e0.css rel=stylesheet>
</head>
<body>
<div id=app></div>
<script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script>
<script type=text/javascript src=./static/js/vendor.ad420f8443715d58c383.js></script>
<script type=text/javascript src=./static/js/app.b8009791bfe7d82cb400.js></script>
</body>
</html>
页面文件如上所示 却访问不到所有的js静态资源
页面文件在webapp/WEB-INF下
js文件在 webapp/WEB-INF/static/js/下
url为localhost:8080/projectName/app/index下
在springMVC配置文件中配置为
<mvc:resources location="/WEB-INF/static/css" mapping="/static/css/**"/>
<mvc:resources location="/WEB-INF/static/js" mapping="/static/js/**"/>
发现静态资源访问失败
最后发现是由于这几个原因导致的!!!
1.由于src为<script type=text/javascript src=./static/js/app.b8009791bfe7d82cb400.js></script>
则静态资源的访问连接为localhost:8080/projectName/app/static.js/xxxxx.js 不在根目录下 所以应该改页面url为localhost:8080/projectName/index
2.配置文件中location最后少了个 “/” 导致解析失败
改为
<mvc:resources location="/WEB-INF/static/css/" mapping="/static/css/**"/>
<mvc:resources location="/WEB-INF/static/js/" mapping="/static/js/**"/>
location表示静态资源地址 mapping表示映射地址
3.spingmvc版本为3.0.0 改为4.0
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
在spingmvc的配置文件中 应用spring-mvc-4.0.xsm 因为<mvc:resource xxx/>标签配置支持springmvc3.0.4以上