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

HttpSession doubt

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Numbers of previous attemptes does not change after second attempt to call the servlet .Please suggest what is the problem with my servlet:--
Here is my servlet code :-
 
Jonathan Elkharrat
Ranch Hand
Posts: 170
Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your ctr variable is local, it's scope is the method only.
try to store it in the session:

if (session.isNew()) {
msg = "Hello new User";
session.setAttribute("counter",ctr);
}
else {
msg = "Welcome back";
ctr=(Integer)session.getAttribute("counter")+1;
session.setAttribute("counter",ctr);
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic