Class PageContext
- java.lang.Object
- 
- javax.servlet.jsp.JspContext
- 
- javax.servlet.jsp.PageContext
 
 
- 
 public abstract class PageContext extends JspContext PageContext extends JspContext to provide useful context information for when JSP technology is used in a Servlet environment. 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. Implicit objects are added to the pageContext automatically. The PageContextclass 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().An example of how PageContext, JspFactory, and other classes can be used within a JSP Page Implementation object is given elsewhere. The PageContext provides a number of facilities to the page/component author and page implementor, including: - a single API to manage the various scoped namespaces
- a number of convenience API's to access various public objects
- a mechanism to obtain the JspWriter for output
- a mechanism to manage session usage by the page
- a mechanism to expose page directive attributes to the scripting environment
- mechanisms to forward or include the current request to other active components in the application
- a mechanism to handle errorpage exception processing
 Methods Intended for Container Generated Code Some methods are intended to be used by the code generated by the container, not by code written by JSP page authors, or JSP tag library authors. The methods supporting lifecycle are initialize()andrelease()The following methods enable the management of nested JspWriter streams to implement Tag Extensions: pushBody()Methods Intended for JSP authors The following methods provide convenient access to implicit objects: getException(),getPage()getRequest(),getResponse(),getSession(),getServletConfig()andgetServletContext().The following methods provide support for forwarding, inclusion and error handling: forward(),include(), andhandlePageException().
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringAPPLICATIONName used to store ServletContext in PageContext name table.static intAPPLICATION_SCOPEApplication scope: named reference remains available in the ServletContext until it is reclaimed.static java.lang.StringCONFIGName used to store ServletConfig in PageContext name table.static java.lang.StringEXCEPTIONName used to store uncaught exception in ServletRequest attribute list and PageContext name table.static java.lang.StringOUTName used to store current JspWriter in PageContext name table.static java.lang.StringPAGEName used to store the Servlet in this PageContext's nametables.static intPAGE_SCOPEPage 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.StringPAGECONTEXTName used to store this PageContext in it's own name table.static java.lang.StringREQUESTName used to store ServletRequest in PageContext name table.static intREQUEST_SCOPERequest scope: the named reference remains available from the ServletRequest associated with the Servlet until the current request is completed.static java.lang.StringRESPONSEName used to store ServletResponse in PageContext name table.static java.lang.StringSESSIONName used to store HttpSession in PageContext name table.static intSESSION_SCOPESession 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 SummaryConstructors Constructor Description PageContext()Sole constructor.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidforward(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.ErrorDatagetErrorData()Provides convenient access to error information.abstract java.lang.ExceptiongetException()The current value of the exception object (an Exception).abstract java.lang.ObjectgetPage()The current value of the page object (In a Servlet environment, this is an instance of javax.servlet.Servlet).abstract javax.servlet.ServletRequestgetRequest()The current value of the request object (a ServletRequest).abstract javax.servlet.ServletResponsegetResponse()The current value of the response object (a ServletResponse).abstract javax.servlet.ServletConfiggetServletConfig()The ServletConfig instance.abstract javax.servlet.ServletContextgetServletContext()The ServletContext instance.abstract javax.servlet.http.HttpSessiongetSession()The current value of the session object (an HttpSession).abstract voidhandlePageException(java.lang.Exception e)This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP.abstract voidhandlePageException(java.lang.Throwable t)This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP.abstract voidinclude(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 voidinclude(java.lang.String relativeUrlPath, boolean flush)Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread.abstract voidinitialize(javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)The initialize method 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 within it's _jspService() method.BodyContentpushBody()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 voidrelease()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().- 
Methods inherited from class javax.servlet.jsp.JspContextfindAttribute, getAttribute, getAttribute, getAttributeNamesInScope, getAttributesScope, getELContext, getExpressionEvaluator, getOut, getVariableResolver, popBody, pushBody, removeAttribute, removeAttribute, setAttribute, setAttribute
 
- 
 
- 
- 
- 
Field Detail- 
PAGE_SCOPEpublic static final 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.- See Also:
- Constant Field Values
 
 - 
REQUEST_SCOPEpublic static final int REQUEST_SCOPE Request scope: the named reference remains available from the ServletRequest associated with the Servlet until the current request is completed.- See Also:
- Constant Field Values
 
 - 
SESSION_SCOPEpublic static final 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.- See Also:
- Constant Field Values
 
 - 
APPLICATION_SCOPEpublic static final int APPLICATION_SCOPE Application scope: named reference remains available in the ServletContext until it is reclaimed.- See Also:
- Constant Field Values
 
 - 
PAGEpublic static final java.lang.String PAGE Name used to store the Servlet in this PageContext's nametables.- See Also:
- Constant Field Values
 
 - 
PAGECONTEXTpublic static final java.lang.String PAGECONTEXT Name used to store this PageContext in it's own name table.- See Also:
- Constant Field Values
 
 - 
REQUESTpublic static final java.lang.String REQUEST Name used to store ServletRequest in PageContext name table.- See Also:
- Constant Field Values
 
 - 
RESPONSEpublic static final java.lang.String RESPONSE Name used to store ServletResponse in PageContext name table.- See Also:
- Constant Field Values
 
 - 
CONFIGpublic static final java.lang.String CONFIG Name used to store ServletConfig in PageContext name table.- See Also:
- Constant Field Values
 
 - 
SESSIONpublic static final java.lang.String SESSION Name used to store HttpSession in PageContext name table.- See Also:
- Constant Field Values
 
 - 
OUTpublic static final java.lang.String OUT Name used to store current JspWriter in PageContext name table.- See Also:
- Constant Field Values
 
 - 
APPLICATIONpublic static final java.lang.String APPLICATION Name used to store ServletContext in PageContext name table.- See Also:
- Constant Field Values
 
 - 
EXCEPTIONpublic static final java.lang.String EXCEPTION Name used to store uncaught exception in ServletRequest attribute list and PageContext name table.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
initializepublic abstract void initialize(javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) throws java.io.IOException, java.lang.IllegalStateException, java.lang.IllegalArgumentExceptionThe initialize method 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 within 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. This method should not be used by page or tag library authors. - Parameters:
- servlet- The Servlet that is associated with this PageContext
- request- The currently pending request for this Servlet
- response- The currently pending response for this Servlet
- errorPageURL- The value of the errorpage attribute from the page directive or null
- needsSession- The value of the session attribute from the page directive
- bufferSize- The value of the buffer attribute from the page directive
- autoFlush- The value of the autoflush attribute from the page directive
- Throws:
- java.io.IOException- during creation of JspWriter
- java.lang.IllegalStateException- if out not correctly initialized
- java.lang.IllegalArgumentException- If one of the given parameters is invalid
 
 - 
releasepublic 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. This method should not be used by page or tag library authors. 
 - 
getSessionpublic abstract javax.servlet.http.HttpSession getSession() The current value of the session object (an HttpSession).- Returns:
- the HttpSession for this PageContext or null
 
 - 
getPagepublic abstract java.lang.Object getPage() The current value of the page object (In a Servlet environment, this is an instance of javax.servlet.Servlet).- Returns:
- the Page implementation class instance associated with this PageContext
 
 - 
getRequestpublic abstract javax.servlet.ServletRequest getRequest() The current value of the request object (a ServletRequest).- Returns:
- The ServletRequest for this PageContext
 
 - 
getResponsepublic abstract javax.servlet.ServletResponse getResponse() The current value of the response object (a ServletResponse).- Returns:
- the ServletResponse for this PageContext
 
 - 
getExceptionpublic abstract java.lang.Exception getException() The current value of the exception object (an Exception).- Returns:
- any exception passed to this as an errorpage
 
 - 
getServletConfigpublic abstract javax.servlet.ServletConfig getServletConfig() The ServletConfig instance.- Returns:
- the ServletConfig for this PageContext
 
 - 
getServletContextpublic abstract javax.servlet.ServletContext getServletContext() The ServletContext instance.- Returns:
- the ServletContext for this PageContext
 
 - 
forwardpublic abstract void forward(java.lang.String relativeUrlPath) throws javax.servlet.ServletException, java.io.IOExceptionThis 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 ServletContextfor 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 Threadexecuting within a_jspService(...)method of a JSP.Once this method has been called successfully, it is illegal for the calling Threadto attempt to modify theServletResponseobject. Any such attempt to do so, shall result in undefined behavior. Typically, callers immediately return from_jspService(...)after calling this method.- Parameters:
- relativeUrlPath- specifies the relative URL path to the target resource as described above
- Throws:
- java.lang.IllegalStateException- if- ServletResponseis not in a state where a forward can be performed
- javax.servlet.ServletException- if the page that was forwarded to throws a ServletException
- java.io.IOException- if an I/O error occurred while forwarding
 
 - 
includepublic abstract void include(java.lang.String relativeUrlPath) throws javax.servlet.ServletException, java.io.IOExceptionCauses 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 ServletContextfor 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 Threadexecuting within a_jspService(...)method of a JSP.- Parameters:
- relativeUrlPath- specifies the relative URL path to the target resource to be included
- Throws:
- javax.servlet.ServletException- if the page that was forwarded to throws a ServletException
- java.io.IOException- if an I/O error occurred while forwarding
 
 - 
includepublic abstract void include(java.lang.String relativeUrlPath, boolean flush) throws javax.servlet.ServletException, java.io.IOExceptionCauses 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 current JspWriter returned by a call to getOut(). If flush is true, The current JspWriter "out" for this JSP is flushed as a side-effect of this call, prior to processing the include. Otherwise, the JspWriter "out" is not flushed. If the relativeUrlPath begins with a "/" then the URL specified is calculated relative to the DOCROOT of the ServletContextfor 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 Threadexecuting within a_jspService(...)method of a JSP.- Parameters:
- relativeUrlPath- specifies the relative URL path to the target resource to be included
- flush- True if the JspWriter is to be flushed before the include, or false if not.
- Throws:
- javax.servlet.ServletException- if the page that was forwarded to throws a ServletException
- java.io.IOException- if an I/O error occurred while forwarding
- Since:
- JSP 2.0
 
 - 
handlePageExceptionpublic abstract void handlePageException(java.lang.Exception e) throws javax.servlet.ServletException, java.io.IOExceptionThis method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP. If forwarding is not possible (for example because the response has already been committed), an implementation dependent mechanism should be used to invoke the error page (e.g. "including" the error page instead). If no error page is defined in the page, the exception should be rethrown so that the standard servlet error handling takes over. 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. This method is kept for backwards compatibility reasons. Newly generated code should use PageContext.handlePageException(Throwable). - Parameters:
- e- the exception to be handled
- Throws:
- javax.servlet.ServletException- if an error occurs while invoking the error page
- java.io.IOException- if an I/O error occurred while invoking the error page
- java.lang.NullPointerException- if the exception is null
- See Also:
- handlePageException(Throwable)
 
 - 
handlePageExceptionpublic abstract void handlePageException(java.lang.Throwable t) throws javax.servlet.ServletException, java.io.IOExceptionThis method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP. If forwarding is not possible (for example because the response has already been committed), an implementation dependent mechanism should be used to invoke the error page (e.g. "including" the error page instead). If no error page is defined in the page, the exception should be rethrown so that the standard servlet error handling takes over. 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. - Parameters:
- t- the throwable to be handled
- Throws:
- javax.servlet.ServletException- if an error occurs while invoking the error page
- java.io.IOException- if an I/O error occurred while invoking the error page
- java.lang.NullPointerException- if the exception is null
- See Also:
- handlePageException(Exception)
 
 - 
pushBodypublic 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.- Returns:
- the new BodyContent
 
 - 
getErrorDatapublic ErrorData getErrorData() Provides convenient access to error information.- Returns:
- an ErrorData instance containing information about the error, as obtained from the request attributes, as per the Servlet specification. If this is not an error page (that is, if the isErrorPage attribute of the page directive is not set to "true"), the information is meaningless.
- Since:
- JSP 2.0
 
 
- 
 
-