Forums Register Login

vector and servlet question...

+Pie Number of slices to send: Send
Hi cowboys n -girls!
Is it possible that I create a vector object in a servlet that still remains when the servlet lifecycle has ended? And can I access it from different servlets??
I think its not that complicated but I don't have that many practise yet :-(
Thx
Tobi
+Pie Number of slices to send: Send
You can make it static so it is available for the lifetime of the servlet class, and not for an instance of the servlet object. If you make it public, other servlets ( and all the other java classes so to speak ) will be able to access it.
[ July 01, 2003: Message edited by: Michael Bronshteyn ]
+Pie Number of slices to send: Send
For per-user persistance, you can stuff your Vector (recommend ArrayList instead) on the session. If it's to be app-persistant, the servlet context (aka application context) is the place to tuck it away.
I'd shy away from a static variable implementation.
hth,
bear
[ July 01, 2003: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Thanks for your answers guys!
Why exactly is an ArrayList better than a Vector?
Because it is easier to access?
+Pie Number of slices to send: Send
See my Collections Crib Sheet for some comparisons of collections. Sun tries to push us to the new Collections, away from Vector and Hashtable.
BTW: Be very careful about synchronization on any member variables, static or not. There can be many threads runing the same servlet at any time.
[ July 02, 2003: Message edited by: Stan James ]
bacon. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 536 times.
Similar Threads
Regarding about sending request attributue from jsp to servlet
synchronization in servlets
Value in dropdown from servlet
unable to solve the problem
How to pass Vector to servlet from a jsp page?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:22:30.