File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

useBean

 
sangeeta kapoor
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my knowledge....
"id" is just a vaiable name which identifies a particular instance of a bean
 
Louis - Jean Morisset
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic