spring MVC资源过滤配置

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"/>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0X码上链

你的鼓将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值