${pageContext.request.contextPath}
是JSP取得绝对路径的方法
也就是取出部署的应用程序名或者是当前的项目名称
比如我的项目名称是myself
在浏览器中输入为localhost:8080/myself
${pageContext.request.contextPath}
取出来的就是localhost:8080/myself
,而http://localhost:8080
用/
代替,所以取出来的路径就是/myself
${pageContext.request.contextPath } 无效大多情况下是由于web.xml
版本太低导致的,现在普遍都再用web4.0版本
下面是4.0的代码,替换掉你的web.xml
即可
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
</web-app>