Servlets: How to reinitialize a variable each time the servlet is accessed ?

M

Multicoder4002

Hi!

I thought that the "reloadable" attribute would do that. But after
reading a little more, I noticed that this attribute make the servlet
reload each time it is overwritten on the server...

So, would anyone know how to reload and reinitialize a servlet each
time it is accessed by a client ? I have coded a servlet and it has an
integer variable declared in the global servlet scope... And each time
the client calls the doget method, I would like the integer i to be
reinitialized to zero...

thanks ;)
 
A

analogueboy

do you mean that you have a static variable that you want to increment at
the end of every doGet method?
 
W

Wendy S

Multicoder4002 said:
So, would anyone know how to reload and reinitialize a servlet each
time it is accessed by a client ? I have coded a servlet and it has an
integer variable declared in the global servlet scope... And each time
the client calls the doget method, I would like the integer i to be
reinitialized to zero...

Can you explain why you want this behavior? In general, class variables are
not a good idea in Servlets, unless you *want* the value to be shared across
all requests.

I think you should move the variable inside the doGet() method, and then
each request will have its own copy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top