<title css='default.css'>PageContext</title>

<objsummary/>

<section title='PageContext'>

<defun title='attribute'>
<sum>This object contains page scope variables.</sum>  In particular,
beans declared with the jsp:useBean page scope are stored in the
pageContext attribute.

<example>
<example>
&lt;% 
  pageContext.attribute.a = 1;
  pageContext.attribute.b = 2;

  for (var name in pageContext.attribute)
    out.writeln(name, ": ", pageContext.attribute[name]); 
%&gt;
</example>
<results>
a: 1
b: 2
</results>
</example>

</defun>

<defun title='out'>
<sum>Returns the JspWriter for this response.</sum>  This is the same
as the JSP 'out' implicit variable.  JspWriter has the same properties and
methods as output <a href='stream.html'>streams</a>.

<example>
<example>
&lt;% 
  pageContext.out.writeln("Hello, world");
%&gt;
</example>
<results>
Hello, world
</results>
</example>

</defun>

<defun title='session'>
<sum>Returns the page's <a href='session.html'>session</a>.</sum>

<example>
<example>
Welcome back.  You've visited
&lt;%= pageContext.session.value++ %&gt; times
</example>
</example>

</defun>

<defun title='servletContext'>
<sum>Returns the page's <a href='application.html'>application</a>
object.</sum>  Along with application variables, the application
object lets scripts dynamically include files and forward results.

<example>
<example>
You are visistor
&lt;%= pageContext.servletContext.attribute++ %&gt;
</example>
</example>

</defun>

<defun title='servlet'>
<sum>Returns the page's generated servlet.</sum>  <note>This is not
the JSP engine's servlet, but the servlet generated for the particular
JSP page.</note>

<example>
<example>
&lt;%@ page info='Special Servlet' %&gt;
&lt;%= pageContext.servlet.servletInfo %gt;
</example>
<results>
Special Servlet
</results>
</example>

</defun>

<defun title='servletRequest'>
<sum>Returns the page's <a href='request.html'>request</a>
object.</sum>  The request object contains information from the HTTP
request, such as form data and allows forwarding pages to pass along
attributes.

<example>
<example>
&lt;%
  var req = pageContext.servletRequest
  for (var key in req.form)
    out.writeln(key, ": ", req.form[key]);
%&gt;
</example>
<results>
name: George Washington
honesty: mythical
</results>
</example>

</defun>

<defun title='servletResponse'>
<sum>Returns the page's <a href='response.html'>response</a>
object.</sum>  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.

<example>
&lt;%
  var res = pageContext.servletResponse
  res.header["Expires"] = new Date().toString()
%&gt;
</example>

</defun>

<defun title='exception'>
<sum>For <a href='jsp-directives.html#errorpage'>error pages</a>,
returns the thrown exception.</sum>

<example>
&lt;%
  response.setStatus(500);
  out.writeln("Exception: ", pageContext.exception)
%&gt;
</example>

</defun>

<defun name='include' title='include(href)'>
<sum>Includes the dynamic contents of the page at <var/href/>.</sum>
<var/href/> is relative to the current page and its root is the
application root.

<p/><code/include/> is the proper way to include JSP generated contents in
the current page.
</defun>

<defun name='forward' title='forward(href)'>
<sum>Includes the dynamic contents of the page at <var/href/>.</sum>
<var/href/> is relative to the current page and its root is the
application root.

<p/><code/forward/> cannot be called after data has returned to the
browser.  Because of JSP's 8k <a
href='jsp-directives.html#buffer'>buffer</a>,  most applications can
ignore this limitation.

</defun>

</section>
