aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "useBean" Watch "useBean" New topic
Author

useBean

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


DKR<br />SCJP1.2,SCWCD1.4,SCBCD1.3,SCJA
Louis - Jean Morisset
Greenhorn

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: useBean
 
Similar Threads
Class Diagram anyone?
JavaBean
Can you prevent another thread from modifying a collection while you iterate over it in EL?
Display messages from controller on top of JSP page
View cannot be restored exception