1、将项目部署到tomcat的ROOT目录下:
从安全的角度,一般将资源放到WEB-INF下,只能通过服务器才能获取资源。
主页映射:
web.xml:
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
applicationMVC.xml:
<!-- 首页跳转 -->
<mvc:view-controller path="/" view-name="index"/>
<mvc:resources mapping="/image/**" location="/WEB-INF/images/" />
<mvc:resources mapping="/js/**" location="/WEB-INF/js/" />
<mvc:resources mapping="/css/**" location="/WEB-INF/css/" />
jsp页面获取资源:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
-->
<%String path = request.getContextPath(); %>
<link href="<%=path %>/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=path %>/css/bootstrap-table.min.css" rel="stylesheet">
<script src="<%=path %>/js/jquery-2.1.1.min.js"></script>
<script src="<%=path %>/js/bootstrap.min.js"></script>
<script src="<%=path %>/js/bootstrap-table.js"></script>
<script src="<%=path %>//js/bootstrap-table-export.js"></script>
<link rel="Shortcut icon" href="../images/favicon.ico" />
<title>配置套餐和资费包</title>
</head>
<!-- For static resources -->
<mvc:resources mapping="/image/**" location="/images/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/html/**" location="/html/" />
<mvc:resources mapping="/software/**" location="/software/" />
下面这种是直接根据静态文件的后缀来配置的,比较通用,不用为每个子目录配置一个:
<mvc:resources location="/" mapping="/**/*.html"/>
<mvc:resources location="/" mapping="/**/*.js"/>
<mvc:resources location="/" mapping="/**/*.css"/>
<mvc:resources location="/" mapping="/**/*.png"/>
<mvc:resources location="/" mapping="/**/*.gif"/>