Re: Obtain object from session in normal class
Wednesday, February 14, 2007 07:30 PM
Putting something like that in a contextlistener (for startup) is pretty much the right way to do it. You wind up putting the object(s) in the application scope (not the session scope), so your servlet/jsp pages can get to them. If you have a user-defined helper class (like a plain old bean), you might need to pass in a reference to the object from the servlet/jsp page. I suppose you could also play with having a static reference in some helper class (and a static getter method) that the contextlistener itself initializes -- then you wouldn't need to pass anything around later. I'm not sure of the design impact of this versus whatever you're going to be designing/working with. Still, the techniques of creating and accessing a static/singleton don't change just b/c a j2ee container has provided the 'main' entry point.