This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "useBean" Watch "useBean" New topic


sangeeta kapoor
Ranch Hand

Joined: Jun 15, 2004
Posts: 70
I create a bean such as

<jsp:useBean id="pref" class="com.Preferences" scope="session" />

What is "pref" in this case. Is it a attribute in session scope or is it a object of com.Preferences class.

Please help me understand this concept.
Deepa Korecherla
Ranch Hand

Joined: Jul 14, 2004
Posts: 197
To my knowledge....
"id" is just a vaiable name which identifies a particular instance of a bean

Louis - Jean Morisset

Joined: Aug 25, 2003
Posts: 20

<jsp:useBean id="pref" class="com.Preferences" scope="session" />

Realy what happens in the background is something equivalent to this.
First it looks in the session to see if the object exists, if it does it gives it back with a reference to it called "pref". If it doesn't exist, it creates the object, puts it in the session and then gives you the reference to it called "pref". So the code would look something like this..

com.Preferences pref = (com.Preferences)req.getSession().getAttribute("pref");
if(pref == null){
com.Preferences pref = new com.Preferences();
req.getSession().setAttribute("pref", pref);
return pref;

Really the last line where I write return pref, I don't know exactly if it returns it like this of some other way to give you the reference to the object, but you get the idea.
[ February 22, 2005: Message edited by: Louis - Jean Morisset ]
wood burning stoves
subject: useBean
jQuery in Action, 3rd edition