|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.jsp.PageContext
A PageContext instance provides access to all the namespaces associated with a JSP page, provides access to several page attributes, as well as a layer above the implementation details.
An instance of an implementation dependent subclass of this abstract base
class is created by a JSP implementation class at the begining of it's
_jspService()
method via an implementation default
JspFactory
, as follows:
public class foo implements Servlet {
// ...
public void _jspService(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
JspFactory factory = JspFactory.getDefaultFactory();
PageContext pageContext = factory.getPageContext(
this,
request,
response,
null, // errorPageURL
false, // needsSession
JspWriter.DEFAULT_BUFFER,
true // autoFlush
);
// initialize implicit variables for scripting env ...
HttpSession session = pageContext.getSession();
JspWriter out = pageContext.getOut();
Object page = this;
try {
// body of translated JSP here ...
} catch (Exception e) {
out.clear();
pageContext.handlePageException(e);
} finally {
out.close();
factory.releasePageContext(pageContext);
}
}
The PageContext
class is an abstract class, designed to be
extended to provide implementation dependent implementations thereof, by
conformant JSP engine runtime environments. A PageContext instance is
obtained by a JSP implementation class by calling the JspFactory.getPageContext() method, and is released by calling JspFactory.releasePageContext().
The PageContext provides a number of facilities to the page/component author and page implementor, including:
Field Summary | |
static java.lang.String |
APPLICATION
name used to store ServletContext in PageContext name table |
static int |
APPLICATION_SCOPE
application scope: named reference remains available in the ServletContext until it is reclaimed. |
static java.lang.String |
CONFIG
name used to store ServletConfig in PageContext name table |
static java.lang.String |
EXCEPTION
name used to store uncaught exception in ServletRequest attribute list and PageContext name table |
static java.lang.String |
OUT
name used to store current JspWriter in PageContext name table |
static java.lang.String |
PAGE
name used to store the Servlet in this PageContext's nametables |
static int |
PAGE_SCOPE
page scope: (this is the default) the named reference remains available in this PageContext until the return from the current Servlet.service() invocation. |
static java.lang.String |
PAGECONTEXT
name used to store this PageContext in it's own name tables |
static java.lang.String |
REQUEST
name used to store ServletRequest in PageContext name table |
static int |
REQUEST_SCOPE
request scope: the named reference remains available from the ServletRequest associated with the Servlet that until the current request is completed. |
static java.lang.String |
RESPONSE
name used to store ServletResponse in PageContext name table |
static java.lang.String |
SESSION
name used to store HttpSession in PageContext name table |
static int |
SESSION_SCOPE
session scope (only valid if this page participates in a session): the named reference remains available from the HttpSession (if any) associated with the Servlet until the HttpSession is invalidated. |
Constructor Summary | |
PageContext()
|
Method Summary | |
abstract java.lang.Object |
findAttribute(java.lang.String name)
Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null. |
abstract void |
forward(java.lang.String relativeUrlPath)
This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application. |
abstract java.lang.Object |
getAttribute(java.lang.String name)
return the object associated with the name in the page scope or null |
abstract java.lang.Object |
getAttribute(java.lang.String name,
int scope)
return the object associated with the name in the specifed scope or null |
abstract java.util.Enumeration |
getAttributeNamesInScope(int scope)
|
abstract int |
getAttributesScope(java.lang.String name)
|
abstract java.lang.Exception |
getException()
|
abstract JspWriter |
getOut()
|
abstract java.lang.Object |
getPage()
|
abstract ServletRequest |
getRequest()
|
abstract ServletResponse |
getResponse()
|
abstract ServletConfig |
getServletConfig()
|
abstract ServletContext |
getServletContext()
|
abstract HttpSession |
getSession()
|
abstract void |
handlePageException(java.lang.Exception e)
This method is intended to process an unhandled "page" level exception by redirecting the exception to either the specified error page for this JSP, or if none was specified, to perform some implementation dependent action. |
abstract void |
include(java.lang.String relativeUrlPath)
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread. |
abstract void |
initialize(Servlet servlet,
ServletRequest request,
ServletResponse response,
java.lang.String errorPageURL,
boolean needsSession,
int bufferSize,
boolean autoFlush)
The initialize emthod is called to initialize an uninitialized PageContext so that it may be used by a JSP Implementation class to service an incoming request and response wihtin it's _jspService() method. |
JspWriter |
popBody()
Return the previous JspWriter "out" saved by the matching pushBody(), and update the value of the "out" attribute in the page scope attribute namespace of the PageConxtext |
BodyContent |
pushBody()
Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext |
abstract void |
release()
This method shall "reset" the internal state of a PageContext, releasing all internal references, and preparing the PageContext for potential reuse by a later invocation of initialize(). |
abstract void |
removeAttribute(java.lang.String name)
remove the object reference associated with the specified name |
abstract void |
removeAttribute(java.lang.String name,
int scope)
remove the object reference associated with the specified name |
abstract void |
setAttribute(java.lang.String name,
java.lang.Object attribute)
register the name and object specified with page scope semantics |
abstract void |
setAttribute(java.lang.String name,
java.lang.Object o,
int scope)
register the name and object specified with appropriate scope semantics |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int PAGE_SCOPE
public static final int REQUEST_SCOPE
public static final int SESSION_SCOPE
public static final int APPLICATION_SCOPE
public static final java.lang.String PAGE
public static final java.lang.String PAGECONTEXT
public static final java.lang.String REQUEST
public static final java.lang.String RESPONSE
public static final java.lang.String CONFIG
public static final java.lang.String SESSION
public static final java.lang.String OUT
public static final java.lang.String APPLICATION
public static final java.lang.String EXCEPTION
Constructor Detail |
public PageContext()
Method Detail |
public abstract void initialize(Servlet servlet, ServletRequest request, ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) throws java.io.IOException, java.lang.IllegalStateException, java.lang.IllegalArgumentException
The initialize emthod is called to initialize an uninitialized PageContext so that it may be used by a JSP Implementation class to service an incoming request and response wihtin it's _jspService() method.
This method is typically called from JspFactory.getPageContext() in order to initialize state.
This method is required to create an initial JspWriter, and associate the "out" name in page scope with this newly created object.
servlet
- The Servlet that is associated with this PageContextrequest
- The currently pending request for this Servletresponse
- The currently pending response for this ServleterrorPageURL
- The value of the errorpage attribute from the page directive or nullneedsSession
- The value of the session attribute from the page directivebufferSize
- The value of the buffer attribute from the page directiveautoFlush
- The value of the autoflush attribute from the page directivepublic abstract void release()
This method shall "reset" the internal state of a PageContext, releasing all internal references, and preparing the PageContext for potential reuse by a later invocation of initialize(). This method is typically called from JspFactory.releasePageContext().
subclasses shall envelope this method
public abstract void setAttribute(java.lang.String name, java.lang.Object attribute)
public abstract void setAttribute(java.lang.String name, java.lang.Object o, int scope)
name
- the name of the attribute to seto
- the object to associate with the namescope
- the scope with which to associate the name/objectpublic abstract java.lang.Object getAttribute(java.lang.String name)
return the object associated with the name in the page scope or null
name
- the name of the attribute to getpublic abstract java.lang.Object getAttribute(java.lang.String name, int scope)
return the object associated with the name in the specifed scope or null
name
- the name of the attribute to setscope
- the scope with which to associate the name/objectpublic abstract java.lang.Object findAttribute(java.lang.String name)
Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.
public abstract void removeAttribute(java.lang.String name)
public abstract void removeAttribute(java.lang.String name, int scope)
public abstract int getAttributesScope(java.lang.String name)
public abstract java.util.Enumeration getAttributeNamesInScope(int scope)
public abstract JspWriter getOut()
public abstract HttpSession getSession()
public abstract java.lang.Object getPage()
public abstract ServletRequest getRequest()
public abstract ServletResponse getResponse()
public abstract java.lang.Exception getException()
public abstract ServletConfig getServletConfig()
public abstract ServletContext getServletContext()
public abstract void forward(java.lang.String relativeUrlPath) throws ServletException, java.io.IOException
This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application.
If the relativeUrlPath begins with a "/" then the URL specified
is calculated relative to the DOCROOT of the ServletContext
for this JSP. If the path does not begin with a "/" then the URL
specified is calculated relative to the URL of the request that was
mapped to the calling JSP.
It is only valid to call this method from a Thread
executing within a _jspService(...)
method of a JSP.
Once this method has been called successfully, it is illegal for the
calling Thread
to attempt to modify the
ServletResponse
object. Any such attempt to do so, shall result
in undefined behavior. Typically, callers immediately return from
_jspService(...)
after calling this method.
relativeUrlPath
- specifies the relative URL path to the target resource as described above ServletResponse
is not in a state where a forward can be performedpublic abstract void include(java.lang.String relativeUrlPath) throws ServletException, java.io.IOException
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread. The output of the target resources processing of the request is written directly to the ServletResponse output stream.
The current JspWriter "out" for this JSP is flushed as a side-effect of this call, prior to processing the include.
If the relativeUrlPath begins with a "/" then the URL specified
is calculated relative to the DOCROOT of the ServletContext
for this JSP. If the path does not begin with a "/" then the URL
specified is calculated relative to the URL of the request that was
mapped to the calling JSP.
It is only valid to call this method from a Thread
executing within a _jspService(...)
method of a JSP.
relativeUrlPath
- specifies the relative URL path to the target resource to be includedpublic abstract void handlePageException(java.lang.Exception e) throws ServletException, java.io.IOException
This method is intended to process an unhandled "page" level exception by redirecting the exception to either the specified error page for this JSP, or if none was specified, to perform some implementation dependent action.
A JSP implementation class shall typically clean up any local state prior to invoking this and will return immediately thereafter. It is illegal to generate any output to the client, or to modify any ServletResponse state after invoking this call.
e
- the exception to be handledpublic BodyContent pushBody()
public JspWriter popBody()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |