为什么要写绝对路径?
是因为有时候编写jsp代码时,系统有时候找不到某某文件或者网页,就必须写一个绝对路径得到某信息。
1、写法${pageContext.request.contextPath}/
比如:
<script type="text/javascript" src="${pageContext.request.contextPath}/js/index.js"></script>
或者
<a href="${pageContext.request.contextPath}/product-list.jsp">
2、注意:绝对路径写在js中不管用
比如:
$(".show").append("<a href="${pageContext.request.contextPath}/product-list.jsp">"):
这样子写添加的a标签路径,点击时报错404,找不到${pageContext.request.contextPath}/product-list.jsp这样路径的页面