Monday, April 26, 2010

Difference between page and pageContext

  page  and pageContext are implicit variables.

   page :   page is of class java.lang.Object,and it refers to instance of generated servlet.It is declared as

          Object page=this;

                          // this refers to the instance of this servlet

     page cannot be used to directly call the servlet methods.

1) <%=page.getServletInfo()%>

  Error bcoz page is  java.lang.Object type

 2)          <%=((servlet)page).getServletInfo()%>  <----OK:typecast

    3)       <%=this.getServletInfo()%> <-------OK

pageContext :

           pageContext is of type javax.servlet.jsp.PageContext.

          pageContext class is an abstract class.

it do following things;

 1.provide convenience methods to get and set attributes in diff scopes.

 2.provide convenience methods for transfering requests to other resources in the web application

      void include(String relativeURL)  & void forward(String relativeURL)

  Ex; pageContext.forward("suman.jsp");

3.store the references to implicit objects


You might also like ..


SHARE & SAVE
Delicious Digg Furl Stumbleupon Technorati Squidoo Reddit live Yahoo MySpaceGoogle Yahoo Buzz Facebook Twitter Orkut Google Buzz Email this postby bbP

No comments: