Friday, April 27, 2012

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 because 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 does the 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("kiran.jsp");

3.store the references to implicit objects

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Page and Pagecontext are implicit objects in jsp. These are created at JSP translated time. The page object represents the generated servlet instance itself and is used as a scope with in one jsp. Pagecontext is used to initilize all implicit objects for example :- page attributes, access to the request, response and session objects, as well as the JspWriter referenced by out. Refer Servlet And JSP Interview Questions to read servlet and jsp interview questions

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.thanks !!

    android training in chennai

    android online training in chennai

    android training in bangalore

    android training in hyderabad

    android Training in coimbatore

    android training

    android online training




    ReplyDelete