Forums Register Login

creating a persistent object at load time?

+Pie Number of slices to send: Send
Say I have an object I want to make available server-wide, and instantiated when tomcat starts up... How would I do this?
I have a hash of numbers to strings that is in a database, I'd like to load the values from the DB and make it available to all jsps and servlets so I don't have to hit the DB all the time.
+Pie Number of slices to send: Send
The easiest way to acheive this is to perform the opertaion in the init() method of a servlet that is flagged in the web.xml as being loaded on start up.
i.e.

Hope this helps
+Pie Number of slices to send: Send
And then a great way to make it available to everything else is to store it as an attribute on the servlet context.
hth,
bear
+Pie Number of slices to send: Send
You guys rock, thanks!
Liar, liar, pants on fire! refreshing plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 524 times.
Similar Threads
Need help regarding s:select tag list
Hibernate: object presistent mapping question
Starting OCMJD
DB Connection Question for MySQL
Zipping of objects in Memory
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:13:29.