posts - 431,  comments - 344,  trackbacks - 0
事例:
<%
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 周锐 阅读(1504) 评论(0)  编辑  收藏 所属分类: Jsp

只有注册用户登录后才能发表评论。


网站导航: