This week's book giveaway is in the
We're giving away four copies of
and have Sam Newman on-line!
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
this week in the
how do I access object populated in servlet
Joined: Aug 13, 2002
Dec 19, 2006 14:00:00
I am populating data from database in an object inside the init method os the
then I am configuring this servelet in web.xml to load on start up using<load-on-startup>
public class TestServlet extends
public void init() throws
tm= call to database(not posting actual code in this line)
I am not much familiar with
,my question is how do I access this object- tm in other classes.
Thanks in advance.
Joined: Feb 07, 2004
Dec 19, 2006 14:23:00
Maybe you can assign it to a singleton variable or store as servlet context attribute.
Retire your iPod and start with HD Android music player
| Minimal J2EE container is
Light weight full J2EE stack
and build tool
| Co-author of "Windows programming in Turbo Pascal"
Author and ninkuma
Joined: Jan 10, 2002
Dec 19, 2006 14:29:00
A servlet is a poor choice for this.
If you need to do something at startup that is not specific to a particular servlet, use a context listener instead. And then, as D pointed out, store the object in application scope (servlet context) for later retrieval by other components.
Asking smart questions
Books by Bear
I agree. Here's the link:
subject: how do I access object populated in servlet
Loading a cache in servlet init method
reference Bean from Servlet
Application Session and global variable, either static or hashtable object
database connection in init() of servlet
Flow of data from Init Servlet to jsp
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015