在 JSP 中,pageContext 是一个类型为 PageContext 类的隐式对象。pageContext 对象可用于从以下范围之一设置、获取或移除属性:page、request、session、application。在 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>  

输出

6-1.jpg

6-2.jpg

6-3.jpg

标签: JSP, JSP教程, JSP技术, JSP快速入门, JSP简单用法, JSP编程, JSP下载, JSP基本语法, JSP安装教程, JSP库, JSP指南, JSP基础教程, JSP初级教程, JSP进阶教程