• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making an object accessible to servlets

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't really sure what to name this post or where to put it, so I apologize if I'm littering.

I wrote an object that allows for the manipulation and access of user accounts for a webapp I'm writting. How can I make that object available to all servlets and also be able to ensure a certain line of code is executed if the container (tomcat) restarts or undeploys the app?

Thank you for atleast reading this post,
-D.P.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clarification:
The object loads an xml file of data into a hashmap when it is instantiated, any changes to that hashmap should eventually be saved.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Prene:

I wrote an object that allows for the manipulation and access of user accounts for a webapp I'm writting. How can I make that object available to all servlets


Depends what you mean by "available". If you want to make it so that the object class is available to servlets so that they can instantiate an instance of the class, then be sure that the class is on the claspath and import it into the servlet classes.

If you by "available" you mean to make an instance of the object available (which I suspect is what you may mean by your follow-on question), then storing the instance in application context will make that instance available to all servlets (be sure to account for synchronization when you do).


and also be able to ensure a certain line of code is executed if the container (tomcat) restarts or undeploys the app?


ServletContextListener
[ January 30, 2006: Message edited by: Bear Bibeault ]
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! One more question though;

storing the instance in application context

How is that done? Code-wise?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.String,%20java.lang.Object)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#setAttribute(java.lang.String,%20java.lang.Object)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic