支持JSTL标签库和EL表达式的两个jar包


1.用JSTL标签库和EL表达式
引入JSTL标签库
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
JSTL标签
<c:set var="path" value="${pageContext.request.contextPath}"/>
JavaScript
<script type="text/javascript" src="${path}/statics/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var path = "${path}";
alert(path);
</script>
谷歌F12中可以看到引入JavaScript的路径已经变了

alert弹窗

与 <%=request.getContextPath()%>等价
2.basePath
JSP中Java代码
<%
String basePath = request.getScheme() + "://" + request.getServerName() + ":"+request.getServerPort() + request.getContextPath() + "/";
%>
JavaScript
<script type="text/javascript" src="${path}/statics/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
alert("<%=basePath%>");
</script>
弹窗

解释
request.getScheme() 返回协议的名称 http,和后面的"://" 拼起来就成了 http://
request.getServerName() 这是获取你的服务器的名称,如果你的应用部署在本机那么其就返回localhost或者127.0.0.1 ,这2个是等价的
request.getServerPort() 是你应用使用的端口,比如8080或者80等等
3.<base href="<%=basePath%>">
<base> 标签为页面上的所有链接规定默认地址或默认目标
要在<head></head>下边定义

没有定义时候点击跳转

定义之后

|