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

setting scope of a bean in Servlet

 
Alex Kravets
Ranch Hand
Posts: 476
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alex Kravets
Ranch Hand
Posts: 476
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic