aspose file tools*
The moose likes Servlets and the fly likes setting scope of a bean in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "setting scope of a bean in Servlet" Watch "setting scope of a bean in Servlet" New topic
Author

setting scope of a bean in Servlet

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
If I call my bean from a Servlet, how can I set its scope? Also, is calling a bean by enough, or do I have to initalize it in a different way?

thanks,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

If I call my bean from a Servlet, how can I set its scope?


This makes no sense to me. Calling a bean and putting it into a scope for passing around are two very different things.

After you create the bean (see below), you can set it into one of the scopes using the setAttribute() method of the target scope.

Also, is calling a bean by
MyBean mBean = new MyBean();


This doesn't "call" a bean, it instantiates an instance of one. And yes, this is generally the correct way to instatiate one -- in fact, all beans must have a zero-arg constructor, or it's not a bean.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
right instance, my mistake...
and I guess this is the answer I was looking for http://www.jguru.com/faq/view.jsp?EID=53309
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

Yes, as I said.

One inaccuracy in the article is that HttpSession.putValue() was deprecated two versions ago; use setAttribute() just like with the other contexts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting scope of a bean in Servlet