PageContext
PageContext
attribute | This object contains page scope variables.
out | Returns the JspWriter for this response.
session | Returns the page's session.
servletContext | Returns the page's application object.
servlet | Returns the page's generated servlet.
servletRequest | Returns the page's request object.
servletResponse | Returns the page's response object.
exception | For error pages, returns the thrown exception.
include(href) | Includes the dynamic contents of the page at href.
forward(href) | Includes the dynamic contents of the page at href.
PageContext
### attribute
This object contains page scope variables. In particular, beans declared with the jsp:useBean page scope are stored in the pageContext attribute.
<% pageContext.attribute.a = 1; pageContext.attribute.b = 2; for (var name in pageContext.attribute) out.writeln(name, ": ", pageContext.attribute[name]); %>
a: 1 b: 2
### out
Returns the JspWriter for this response. This is the same as the JSP 'out' implicit variable. JspWriter has the same properties and methods as output streams.
<% pageContext.out.writeln("Hello, world"); %>
Hello, world
### session
Returns the page's session.
Welcome back. You've visited <%= pageContext.session.value++ %> times
### servletContext
Returns the page's application object. Along with application variables, the application object lets scripts dynamically include files and forward results.
You are visistor <%= pageContext.servletContext.attribute++ %>
### servlet
Returns the page's generated servlet. Note: This is not the JSP engine's servlet, but the servlet generated for the particular JSP page.
<%@ page info='Special Servlet' %> <%= pageContext.servlet.servletInfo %gt;
Special Servlet
### servletRequest
Returns the page's request object. The request object contains information from the HTTP request, such as form data and allows forwarding pages to pass along attributes.
<% var req = pageContext.servletRequest for (var key in req.form) out.writeln(key, ": ", req.form[key]); %>
name: George Washington honesty: mythical
### servletResponse
Returns the page's response object. The response object lets application set response headers and status codes. In general, JSP applications will write to the 'out' object instead of using the response object directly.
<% var res = pageContext.servletResponse res.header["Expires"] = new Date().toString() %>
### exception
For error pages, returns the thrown exception.
<% response.setStatus(500); out.writeln("Exception: ", pageContext.exception) %>
### include(href)
Includes the dynamic contents of the page at href. href is relative to the current page and its root is the application root. `include` is the proper way to include JSP generated contents in the current page.
### forward(href)
Includes the dynamic contents of the page at href. href is relative to the current page and its root is the application root. `forward` cannot be called after data has returned to the browser. Because of JSP's 8k buffer, most applications can ignore this limitation.
Copyright © 1998-2000 Caucho Technology. All rights reserved. Last modified: Fri, 31 Mar 2000 18:53:44 -0800 (PST)