Class PageContext


  • public abstract class PageContext
    extends java.lang.Object

    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:

  • 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