在JSP中, pageContext是PageContext类类型的隐式对象。pageContext对象可用于在以下范围之一中设置, 获取或删除属性:页面请求会话应用程序 |
在JSP中, 页面范围是默认范围。 |
pageContext隐式对象的示例
index.html
<html>
<body>
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
</body>
</html>
welcome.jsp
<html>
<body>
<%
String name=request.getParameter("uname");
out.print("Welcome "+name);
pageContext.setAttribute("user", name, PageContext.SESSION_SCOPE);
<a href="second.jsp">second jsp page</a>
%>
</body>
</html>
second.jsp
<html>
<body>
<%
String name=(String)pageContext.getAttribute("user", PageContext.SESSION_SCOPE);
out.print("Hello "+name);
%>
</body>
</html>
输出量
评论前必须登录!
注册