What is difference between page and pageContext in JSP pages?

The page and pageContext are implicit JSP Objects. The page object represents the generated servlet instance itself, i.e., it is same as the "this" keyword used in a Java file. As a result, you do not typically know who the super class is, and consequently do not normally make use of this object or its methods.

The pageContext object represents the environment for the page, containing useful information like page attributes, access to the request, response and session objects, as well as the JspWriter referenced by out. This object also has methods for including another URL's contents, and for forwarding or redirecting to another URL. For example, to forward a request to another resource from in a JSP page, we can do that by using the pageContext variable:

pageContext.forward ("other.jsp"); 
Implicit ObjectClass or InterfacePurpose, Function, or Uses
page java.lang.Object Refers to the generated Servlet class. Since page refers to the generated class and the class implements the Servlet interface, it is a valid cast it to Servlet. And the page variable could also be cast to JspPage or HttpJspPage since these two interfaces are derived from the Servlet interface and are implemented by the generated servlet class. For example,
<%= ((Servlet)page).getServletInfo () %>
pageContext javax.servlet. jsp.PageContext Used for storing and retrieving page-related information and sharing objects within the same translation unit and same request.
Also used as a convenience class that maintains a table of all the other implicit objects. For example,
public void _jspService (
HttpServletRequest request,
HttpServletResponse response
) throws java.io.IOException, ServletException {

try {

application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();

} catch (Throwable t) {
} finally {

Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |