aspose file tools*
The moose likes JSP and the fly likes Use of a page-scoped attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Use of a page-scoped attribute" Watch "Use of a page-scoped attribute" New topic
Author

Use of a page-scoped attribute

Dash Abhisek
Ranch Hand

Joined: Jul 20, 2008
Posts: 63
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

Joined: Aug 15, 2004
Posts: 2874
To use the variable only in that page. Think of <c:set var="" value="" />.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I don't know of any other way of using, setting or getting, a variable in a scriptlet-less page.
Dash Abhisek
Ranch Hand

Joined: Jul 20, 2008
Posts: 63
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dash Abhisek
Ranch Hand

Joined: Jul 20, 2008
Posts: 63
Thanks a lot ,my doubt is cleared
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Jul 20, 2008
Posts: 63
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

Adeel is correct. There is no good reason not to be writing scriptless JSPs at this juncture.
 
Don't get me started about those stupid light bulbs.
 
subject: Use of a page-scoped attribute