aspose file tools*
The moose likes Servlets and the fly likes User log out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "User log out" Watch "User log out" New topic
Author

User log out

Sandra Baker
Greenhorn

Joined: Jul 10, 2002
Posts: 26
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

Joined: May 08, 2000
Posts: 73
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 ]

SCJP2, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: User log out