1、首先,引入jstl.jar夹包
2、在pathTags.jsp中引入常用的标签
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="m" uri="http://java.sun.com/jsp/jstl/functions" %>
3、新建该jsp过程中,会出现下面这段代码,将其预留<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
4、利用core标签,设置基本路径和相对路径
<c:set var="bp" value="<%=basePath%>"></c:set>
<c:set var="pa" value="<%=path%>"></c:set>
5、在其他的jsp页面引入该jsp
<%@ include file="/jsp/pathTags.jsp"%>
6、在js、css和图片等一些文件的路径前加上
<script type="text/javascript" src="${bp}/scripts/jQuery.js"></script>
附
pathTags.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="m" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set var="bp" value="<%=basePath%>"></c:set>
<c:set var="pa" value="<%=path%>"></c:set>