This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes instance variables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "instance variables" Watch "instance variables" New topic
Author

instance variables

Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 169
Im still new to servlet/jsp subject, and I've a question,
since the variable inside the init() is instance, how is it possible to make a servlet/jsp have a different counter for each instance servlet?
Example: User A and B accesing the same servlet page.
User A has a counter 0 and everytime it refreshes it accumulates
User B has same procedure but the counter is independent from User A.
Thanks.
Rajesh Kumar
Greenhorn

Joined: Oct 25, 2003
Posts: 6
Generally there is only one instance of a servlet, and multiple
client requests result in multiple threads each calling the service method
of the single servlet instance.
If you want to count how many times each user accesses the
page (=servlet) you may want to use a session variable.
something like this, in your doGet for example


HTH
-Rajesh
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 169
Hmm , ok, it's not really possible with the request object. Thanks Rajeesh.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Nelson Nadal:
Hmm , ok, it's not really possible with the request object. Thanks Rajeesh.


Hi Nelson,

Even it is possible with request object by using Hidden form fields or URL rewriting, Cookies technologies (Basically all the session tracking methods will support).
Regards,
M.S.Raman
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: instance variables
 
Similar Threads
counter is not resetting
Servlet specific attribute
Buffer size
JSP variable declarations
Is the values variables declared in Servlets changes when multiple requests comes?