This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instance variables

 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm , ok, it's not really possible with the request object. Thanks Rajeesh.
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic