Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes instance variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
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://aspose.com/file-tools
 
subject: instance variables
 
Similar Threads
Is the values variables declared in Servlets changes when multiple requests comes?
JSP variable declarations
Servlet specific attribute
Buffer size
counter is not resetting