• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of a page-scoped attribute

 
Dash Abhisek
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I don't understand why anyone will use a page-scoped attribute ,the attribute will have a lifetime till the control is in that page so, why should anyone will be setting and getting an attribute in the same page?

Thanks
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use the variable only in that page. Think of <c:set var="" value="" />.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know of any other way of using, setting or getting, a variable in a scriptlet-less page.
 
Dash Abhisek
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
But, if i am having access to a variable then what is the point in setting it in an attribute and getting it from that attribute ?

Thanks
Abhisek
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64832
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same reason that anyone would need a local variable within a Java method. For information of short duration needed for the current unit.

Would you really want to store temporary values (such as loop counters and the like) in any other scope?
[ October 29, 2008: Message edited by: Bear Bibeault ]
 
Dash Abhisek
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot ,my doubt is cleared
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dash Abhisek:
But, if i am having access to a variable then what is the point in setting it in an attribute and getting it from that attribute ?


You don't have the access to any variable, in the case of scriptlet-less page, without setting it in a scope.
[ October 29, 2008: Message edited by: Adeel Ansari ]
 
Dash Abhisek
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adeel,

no where I have mentioned I am using a scriptless jsp.I am talking about
jsps in general nevertheless my doubt is cleared
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dash Abhisek:
no where I have mentioned I am using a scriptless jsp.


I know but you should. Otherwise, you don't need quite a few things and you assume those useless or doesn't serve any purpose.

Moreover, example given by Bear, also has been made by keeping scriptless JSP in mind, I believe.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64832
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adeel is correct. There is no good reason not to be writing scriptless JSPs at this juncture.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic