下列是testOne.jsp页面代码:
<%
String name = "page";
pageContext.setAttribute("name",name);
%>
<strong>
testOne:<%=pageContext.getAttribute("name") %>
</strong>
<br/>
<%
pageContext.include("testTwo.jsp");
%>
下列是testTwo.jsp页面代码:
<strong>
testTwo:<%=pageContext.getAttribute("name") %>
</strong>
页面输出:testOne:page testTwo:null
page作用域,指本JSP页面的范围
最新推荐文章于 2022-05-02 21:46:14 发布
本文通过两个JSP页面的示例,展示了如何在一个页面中设置属性并在另一个被包含的页面中获取这些属性。示例中,testOne.jsp设置了一个名为name的属性,并在页面中显示出来;然后使用pageContext.include()方法包含了testTwo.jsp,但在这个被包含的页面中尝试获取name属性时却得到了null值。
873

被折叠的 条评论
为什么被折叠?



