在JSP中,脚本化语言如“<%=contextPath%>”可以从page,request,session及application中取值。
下面的代码可以看到结果是因为contextPath被保存在page中:
<% String contextPath = request.getContextPath(); %>
<form action="<%=contextPath%>/sub/submit.jsp" method="post">
</form>
EL表达式如“${contextPath}”只能从request,session及application中取值。
上述代码修改一下就可以支持EL表达式:
<%
String contextPath = request.getContextPath();
// 将contextPath保存到request中
request.setAttribute("contextPath", contextPath);
%>
<form action="${contextPath}/sub/submit.jsp" method="post">
</form>
JSP中EL表达式的取值范围
最新推荐文章于 2018-11-25 19:55:41 发布