This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About pageContext.SESSION_CONTEXTand page scope

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the example here:
http://beginnersbook.com/2013/11/jsp-implicit-object-pagecontext-with-examples/


From this example:


The attributes UName is set as page scope.


It is an instance of javax.servlet.jsp.PageContext. Using this object you can find attribute, get attribute, set attribute and remove attribute at any of the below levels –

JSP Page – Scope: PAGE_CONTEXT
HTTP Request – Scope: REQUEST_CONTEXT
HTTP Session – Scope: SESSION_CONTEXT
Application Level – Scope: APPLICATION_CONTEXT


As this quote says, an attribute has 4 different levels of scopes.
The attribute UName's scope is page scope which is only limited to the current JSP.

But why UName is also associated with session scope?
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Himai,


UName is session scope. You are confusing pageContext and PAGE_CONTEXT. If I do this:


This means your attribute will be available in page scope. But if you do this:


Now you are setting the attribute in session scope i.e. it's the same as doing this:

The pageContext is an object of type PageContext and you can check the documentation of setAttribute method...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic