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 Object | Class or Interface | Purpose, 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 ( |
Most Viewed jsp Faqs
- What is difference between page and pageContext in JSP pages?(5999)
- How to retrieve values from HTML form input elements in JSP?(5112)
- How to config a JSP file in web.xml?(4818)
- How to disable browser caching for a specific JSP?(4523)
- What is the difference between jsp:forward and response.sendRedirect?(3519)
- How to get the current JSP page name?(3327)
- What is the difference between request.getParameter() and request.getAttribute()?(3223)
Most Recent jsp Faqs
- What is the difference between request.getParameter() and request.getAttribute()?
- What is difference between page and pageContext in JSP pages?
- How to config a JSP file in web.xml?
- What is the difference between jsp:forward and response.sendRedirect?
- How to retrieve values from HTML form input elements in JSP?
- What are the request and response implicit objects?
- How to get the current JSP page name?