| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs JSP FAQ:
What is the pageContext implicit object?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
|||||||||
What is the
|
| PageContext | ||
|---|---|---|
void include (String relativeURL)
|
Includes the output of another
resource in the output of the current page.
Same as ServletRequest.getRequestDispatcher ().include (); |
|
void forward (String relativeURL)
|
Forwards the request to another
resource.
Same as ServletRequest.getRequestDispatcher ().forward (); |
For example, to forward a request to another resource from a servlet, we have to write the following to lines:
RequestDispatcher rd = request.getRequestDispatcher ("other.jsp");
rd.forward (request, response);
In a JSP page, we can do that in just one line by using the pageContext variable:
pageContext.forward ("other.jsp");
The pageContext object has a type of javax.servlet.jsp.PageContext and according to the API documents:
"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"
A PageContext instance is obtained by a JSP implementation class by calling the JspFactory.getPageContext() method, and is released by calling JspFactory.releasePageContext().
- 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