my dog learned polymorphism
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Diff between page and pageContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Diff between page and pageContext" Watch "Diff between page and pageContext" New topic

Diff between page and pageContext

Sairam Ramakrishnan

Joined: Mar 27, 2004
Posts: 13

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.


************<br />SCJP 1.4
Rizwan Mohammad
Ranch Hand

Joined: Sep 02, 2005
Posts: 445
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

Joined: Oct 18, 2005
Posts: 16
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.

Cheers,<br />Priyank<br />SCJP-96%,SCWCD-85%
Sairam Ramakrishnan

Joined: Mar 27, 2004
Posts: 13
Thank you very much.
I agree. Here's the link:
subject: Diff between page and pageContext
It's not a secret anymore!