jsp、css中引入外部资源相对路径的问题
在jsp页面中添加base,可用相对路径:
<% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %>
然后在<head>标签内添加base
<base href="<%=basePath%>"></base>
在本页面中“直接”引入外部文件时,可直接
<script src="js/common/jquery-1.11.1.min.js" language="javascript" type="text/javascript"></script> <script src="js/common/frame.js" language="javascript" type="text/javascript"></script> <link href="css/common/frame.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
同理,本页面中的css类
.top {
position: absolute;
left: 0;
top: 95px;
right: 0;
height: 120px;
background: url(images/common/title.jpg) repeat-x
}