项目的路径没有显示在jsp页面中,我想导出这句话$ {pageContext.request.contextPath}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="basePath" scope="request">${pageContext.request.contextPath}</c:set>
<%
response.setHeader("Cache-Control","no-catch");
response.setHeader("Pragma","no-catch");
response.setDateHeader("Expires",0);
String a=request.getContextPath();
System.out.println(a);
%>
<html>
<head>
<meta charset="utf-8"/>
<title>code-serv-web</title>
</head>
<body>
<h1>code-serv-web</h1>
<button id="but">点击</button>
</body>
</html>
为什么不在jsp页面中显示$ {pageContext.request.contextPath}
答案 0 :(得分:0)
El表达式应该在JSP页面中写入。
$ {pageContext中。请求。 ContextPath}是通过get方法获取样本的,首先是pageContext。 GetRequest()得到它,然后调用它getContextPath方法 &LT; %%&gt;你必须使用pageContext。 GetRequest(),这个要点一定不能出来,而且它没有这个属性。 其作用是删除已部署的应用程序名称,以使路径正确,无论其部署方式如何。
El表达式方法:$ {pageContext。请求。的contextPath}
JSP编写于:&lt; %= request.getcontextpath()%&gt;
答案 1 :(得分:0)
EL表达式${}
可以在JSP文件中运行,而不是在HTML文件中运行。
您的案例中有两种解决方案
filename.html
重命名为filename.jsp
或
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>