Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Attributes Scope

 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We can have attributes in different scopes in a JSP page. Suppose there is an attribute named 'name' with values in different scopes as below:

request - A
session - B
application - C
page - D

Suppose I print ${name} in a JSP page, then what will be the value printed on the JSP? And, what will be the preference order of attributes search in different scopes?

Thanks & Regards,
Vaibhav Garg
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vaibhav G Garg wrote:what will be the preference order of attributes search in different scopes?


Page, request, session, application.
 
Yogesh Gandhi
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vaibhav,

I had set name attribute in session in controller.
And later on JSP i tried to access it via <c:out value="${name}"/>

On some JSP's I was able to access it, but on one of the JSP's i was getting a value blank (where as on other pages it was working fine).

When I changed it to ${sessionScope.name} it worked...But I don't know why?
By default it also reads from sessionScope if the variable is set in session, Isn't it?

If it doesn't reads from session, how come it was working on other pages?

Does any body has any clue, why adding sessionScope. made it to work.

Regards
Yogesh
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Might be that you set that attribute in page or request scope with empty value in a place you are not aware of, by using sessionScope you are forcing to get the value from the session.
 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yogesh Gandhi wrote:Vaibhav,

And later on JSP i tried to access it via <c:out value="${name}"/>

If it doesn't reads from session, how come it was working on other pages?

Does any body has any clue, why adding sessionScope. made it to work.



Please check the attributes in request scope and print them on JSP page. Most probably, as Albareto mentioned that it might be getting populated in the request attributes somewhere and, hence might be the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!