Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between Page and PageContext  RSS feed

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please clarify the difference between Page and PageContext impilcit objects in jsp ?

page : page is of class java.lang.Object,and it refers to instance of generated servlet. // what does this mean ?

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

Am not able to get the difference between these both, please assist.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask JSP questions in the JSP forum. I have moved this post there for you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are implemented by generating a servlet. The page variable refers to the servlet instance.

As your JSP should not have any Java code in it, this is no longer useful.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it means ...

with page ... you can work with the servlet

with pageContext you can work with the jsp
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lalit Mehra wrote:with page ... you can work with the servlet , for example setting attributes

No. That is not the way to deal with "attributes" (scoped variables).
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
No. That is not the way to deal with "attributes" (scoped variables).


Then how do we use page in real ... ???

I mean we use it in our jsp page as <@ page ... >

what else ???
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've already pointed out that it is completely useless in modern JSP. In fact, it was pretty useless in ancient JSP as well. I never used it for anything.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks DEAR Mr. Bear
 
Nilesh Miskin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
page & pageContext both are implicit objects in a JSP.
page is of type java.lang.Object & refers to the instance of servlet generated from 'this' JSP.
pageContext is of type javax.servlet.jsp.PageContext.
It does following:
1. provides methods to get & set attributes in different scopes.
2. provides methods to include or forward the current request to other active componets in the application
3. provides a mechanism to handle errorpage exceptionn processing.
4. provides mechanism to manage session usage by the page

As Bear suggested, there are better ways to deal with attributes in different scopes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!