• Post Reply Bookmark Topic Watch Topic
  • New Topic

ServletContext doubt ?

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,,

I am new to java servlets, and i want to do this ..

I created a class which implemnts ServletContextListener interface. In this class i override 'contextInitialized(ServletContextEvent sce)' abstract method which instantiated an object Of SomeClass . Now i want this object to be accessible to only one Servlet .. Is it possible to this using ServletContext , if yes , then How ?? OR any other way ?


Thanks in advance..

Regardz,
[ April 03, 2008: Message edited by: Sagar Rohankar ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the ServletContext (accessible from ServletContextEvent) to store any objects using the setAttribute method. Those are accessible by all servlets, though. Generally I wouldn't consider that a problem - if other servlets are not supposed to use that object, then, well, they shouldn't use it. Or do you have reason to mistrust what other servlets are doing?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Ulf Dittmer , thats solve my problem..

Thanks again..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!