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

User log out

 
Sandra Baker
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using Tomcat Form authentication to have user login. Is there anyway I can add a link or button that user can logout whenever he/she intends to?
<% HttpSession ses = request.getSession(true);
if (ses != null){
ses.invalidate();
}
%>
Sorry, I am really new to jsp/servlet... thanks
 
Adrian Muscalu
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sandra Baker:
Hi,
I am using Tomcat Form authentication to have user login. Is there anyway I can add a link or button that user can logout whenever he/she intends to?
<% HttpSession ses = request.getSession(true);
if (ses != null){
ses.invalidate();
}
%>
Sorry, I am really new to jsp/servlet... thanks

Your ses object will never be null in your code since by default the session is created and even more, you enforce it's creation by specifying 'true' as argument.
A button by itself will not help since is executed on the client side. The session invalidation should be made on the server side, in a jsp or a servlet. If your button triggers a page load i.e. logout.jsp, then you can invalidate the session in this page.
Hope this helps,
Adrian
SCJP, SCWCD
[ December 19, 2002: Message edited by: Adrian Muscalu ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic