page implicit object

The JSP implicit page object is an instance of the java.lang.Object class. It represents the current JSP page. That is, it serves as a reference to the java servlet object that implements the JSP page on which it is accessed. It is not advisable to use this page implicit object often as it consumes large memory.

The page variable is an alias for this, which refers to the servlet instance. It wasn’t really very useful when scriptlets were in vogue, and is now completely useless in scriptless pages.

The page implicit object is of type Object and it is assigned a reference to the servlet that executing the _jspService() method. Page is the instance of the JSP page’s servlet processing the current request. Not typically used by JSP page authors. Thus in the Servlet generated by tomcat the page object is created as

Object page = this;

Since page is a variable of type Object, it cannot be used to directly call the servlet methods. To access any of the methods of the servlet through page it must be first cast to type Servlet.

<%= this.getServletInfo(); %>
<%= ((Servlet)page).getServletInfo(); %>

But the following code will generate error, because can not use page directly without casting:

<%= page.getServletInfo(); %>

<<Previous <<   || Index ||   >>Next >>
Previous
Next