JSP基础---pageContext对象
2014-02-21 20:44
399 查看
pageContext对象
pageContext对象是javax.servlet.jsp.PageContext类的实例,主要表示的是一个JSP页面的上下文,在此类中除了之前讲解过的属性操作之外,还定义了以下的一些方法:
1):public abstract void forward(String relativeUrlPath)
2):public void include(String relativeUrlPath)
3):public ServletConfig getServletConfig()
4):public ServletContext getServletContext()
5):public ServletRequest getRequest()
6):public ServletResponse getResponse()
7):public HttpSession getSession()
pageContext主要的功能是在JSP文件中的支持,而且一定要记住的是,pageContext功能强大,几乎可以操作各种内置对象。
pageContext是一个功能强大的内置对象,所以以后在讲解JSP高端编程的时候,标签库编程基本上就要使用pageContext对象完成了。
下面使用pageContext完成一次跳转功能。
【pagecontext_01.jsp内容如下:】
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title>pageContext</title></head>
<body>
<%
pageContext.forward("pagecontext_02.jsp?info=skewrain");
%>
既然现在是跳转,则肯定是可以传递参数的,那么采用地址重写的方式完成的参数传递。
【pagecontext_02.jsp内容如下:】
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title>pagecontext</title></head>
<body>
<%
//直接从pageContext对象中取得了request
String info = pageContext.getRequest().getParameter("info");
%>
<h3>info = <%=info%></h3>
<h3>realpath = <%=pageContext.getServletContext().getRealPath("/")%></h3>
</body>
</html>
执行pagecontext_01.jsp的结果如下:
Info参数已经被传递过来了,而且此时的跳转类型是属于服务器端跳转的,realpath为虚拟目录对应的真实路径。
小结:
1):pageContext中可以取得request、session等主要内置对象;
2):通过pageContext对象可以完成页面的跳转功能。
pageContext对象是javax.servlet.jsp.PageContext类的实例,主要表示的是一个JSP页面的上下文,在此类中除了之前讲解过的属性操作之外,还定义了以下的一些方法:
1):public abstract void forward(String relativeUrlPath)
2):public void include(String relativeUrlPath)
3):public ServletConfig getServletConfig()
4):public ServletContext getServletContext()
5):public ServletRequest getRequest()
6):public ServletResponse getResponse()
7):public HttpSession getSession()
pageContext主要的功能是在JSP文件中的支持,而且一定要记住的是,pageContext功能强大,几乎可以操作各种内置对象。
pageContext是一个功能强大的内置对象,所以以后在讲解JSP高端编程的时候,标签库编程基本上就要使用pageContext对象完成了。
下面使用pageContext完成一次跳转功能。
【pagecontext_01.jsp内容如下:】
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title>pageContext</title></head>
<body>
<%
pageContext.forward("pagecontext_02.jsp?info=skewrain");
%>
既然现在是跳转,则肯定是可以传递参数的,那么采用地址重写的方式完成的参数传递。
【pagecontext_02.jsp内容如下:】
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title>pagecontext</title></head>
<body>
<%
//直接从pageContext对象中取得了request
String info = pageContext.getRequest().getParameter("info");
%>
<h3>info = <%=info%></h3>
<h3>realpath = <%=pageContext.getServletContext().getRealPath("/")%></h3>
</body>
</html>
执行pagecontext_01.jsp的结果如下:
Info参数已经被传递过来了,而且此时的跳转类型是属于服务器端跳转的,realpath为虚拟目录对应的真实路径。
小结:
1):pageContext中可以取得request、session等主要内置对象;
2):通过pageContext对象可以完成页面的跳转功能。
相关文章推荐
- JspContext对象与PageContext对象
- jsp/servlet第五章第五节pagecontext对象
- JSP内置九个对象;pageContext对象;JSP的7个动作指令
- JavaWeb之 JSP:内置对象,EL表达式,JSP标签基础
- jsp中的pagecontext对象
- #笔记#圣思园 JavaWeb 第12讲——JSP基础知识、语法、内置对象、表单、客户机交互
- JSP内置对象详解4 之 page、out、exception、config、pageContext 内置对象
- JavaWeb之 JSP:内置对象,EL表达式,JSP标签基础
- jsp九大内置对象(二)session、application、pageContext
- Jsp中的PageContext隐式对象详解
- JSP的9个内置对象之pageContext对象
- JSP内置对象--4种属性范围 (pageContext,request,session,application)
- pageContext对象、JSP的标签和映射
- JSP(1)之web开发基础、JSP语法及内置对象
- JSP内置对象之application、out、pageContext、config、page、exception
- JSP---WEB安全性及config对象、pagecontext
- jsp内建对象pageContext
- 【夯实基础】JSP的9个内置对象
- Jsp中的pageContext对象
- JSP基础(三)JSP内置对象 利用application对象做一个简单的网页计数器