- 假设项目的请求根路径是/demo
方式一:EL表达式
<form action="${pageContext.request.contextPath}/com/getClicomdetailList.do">
- html中则不是这样
background-image:url(${request.contextPath}/images/3.jpg)
- html中则不是这样
方式二:小脚本
<%=request.getContextPath() %><br> //显示结果:/demo <script src="<%=request.getContextPath() %> /home/test.js"></script>
方式三:c标签
<c:url value="/index.jsp"></c:url><br> //显示结果:/demo/index.jsp
-方式四:js
<script type="text/javascript">var baseUrl='<%=request.getContextPatn() %>';</script><br> //显示结果:baseUrl="/demo"