• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff between page and pageContext

 
Sairam Ramakrishnan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May be this is a simple question.

Can someone tell me the difference between page and pageContext in JSP.

I understand that we get the reference of all the implicit object from pageContext but why does it have an setAttribute() method ? and what is the scope ?

Many thanks.

-Sairam.
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Using pageContext object you can set attribute in one of the scopes page, request, session or application. These scopes are defined as constants in PageContext class and you can pass the scope to the method of setAttribute() to specify in which scope you need to bind the value.
 
Priyank Nautiyal
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your 2nd question has already been answered by Rizwan, so i'll answer your 1st question.
The page object in JSP refers to the servlet that is generated after translation of a JSP i.e. it is same as the "this" keyword used in a Java file, while pageContext is a page scope object similar to request,session and application. So it is the pageContext object which refers to the page scope and not the page object as we might tend to think.
 
Sairam Ramakrishnan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic