• Post Reply Bookmark Topic Watch Topic
  • New Topic

application scope  RSS feed

 
Erik Lindholm
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use this in one of my JSPs:
<jsp:useBean id="MyBean" class="mypackage.MyBean" scope="application" />
My question is:
What would this code be if I should code the same in a Servlet ?
 
Tina Coleman
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, your intended effect is you want all requests to the servlet to be able to access the same MyBean instance? Two possible solutions, I believe.
The first solution would to make MyBean a member of your servlet class. Then, all requests to your servlet would go through your servlet instance, and thus would have access to MyBean.
The second solution would be to put MyBean into the ServletContext, where it can then be shared by _all_ servlets in the servlet engine (or, according to my copy of Marty Hall's book, "or in the Web application, if your server supports such a capability").
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!