事例:
<%
String newImg="yes";
request.setAttribute("newImg",newImg);
%>
${newImg}
<c:set var="newImg1" value="${'10'}"/>
${newImg1}
<%= pageContext.getAttribute("newImg1")%>
原理:
jstl中的變量在賦值<c:set>的時候有個scope屬性,它是用來設置該變量的作用域的,可以是
page
request
session
application
默認是page,同一jsp頁面有效
這四個scope對應在jsp中可以通過
pageContext.getAttribute()
request.getAttribute()
session.getAttribute()
application.getAttribute()
得到值。
如下:
<c:set var="a" value="hello a" scope="request" />
<c:set var="b" value="hello b"/>
<%
out.print(request.getAttribute("a") + "<br/>");
out.print(pageContext.getAttribute("b"));
%>
同理,也可以從jsp中得到變量放入jstl的變量中。
posted on 2007-01-19 15:40
周銳 閱讀(1517)
評論(0) 編輯 收藏 所屬分類:
Jsp