Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2008, 12:52 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
[SOLVED] logout user when session expires
Hi All,

I have developed a web application. In which i want to add logout functionality. For this i used HttpSessionListener, but not working as i wanted.

I marked user logout in sessionDestroyed() method(by updating Database).

If session is timeout then container calls the sessionDestroyed() method and i update the Database but when i explicitly call session.invalidate() (when user click on logout link)values are unbind from session object but container does not call sessionDestroyed() method so not able to update database.

and also need to logout user when user closes browser window.


Please give your valuable idea on the same.

sanjeev
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-11-2008, 08:07 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Hi Dear all,

I got the solution itself.

Thanks for your time.


sanjeev
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 08:13 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Hei Sanjeev Can you please explain how you did it?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 08:37 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road

I implemented HttpSessionListener interface and there are two methods

sessionDestroyed() and sessionCreated(). Nothing to do with session created.
I just updated database in sessionDestroyed() method, and i will be called by container just before session.invalidate() is called.

and added the listener entry into web.xml file.

There are three chances from where user can be marked as logout.
1. Session timeout by container.
2. User clicks on Logout link
3 User close the browser window.

In First case Listener is called by Container and Database is updated.
In second case i called a servlet that do the session.invalidate() and calles a method to update Database.
In 3rd case : When user closes the browser window i called the same servlet from scripts and updated the Database


If still you have any doubts the please feel free to ask anything.


sanjeev
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 08:44 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Hei Sanjeev,
My doubt is why are you updating each time the database

when Session Expires? Can You Please Explain?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 08:58 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Not each time dear....just one time from any one of three condition....for particular one user.


sanjeev
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 08:59 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Ok,
That means you are tracking active users of app and storing to db?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 09:03 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Ya exactly,


we need to track only users who are logged in.


sanejev
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-11-2008, 09:04 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
OK sanjeev,
Thank you.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 04-11-2008, 09:23 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Sanjeev, I have one question.

You are talking about three chances which can be caused to user logout. Fine. How did you check the port. Is there any service is implemented by you to check that port is available.

It can be a cause, if the user have firewall used, isn't it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 04-11-2008, 09:52 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Hi Eranga,

How did you check the port. Is there any service is implemented by you to check that port is available.....?

Why i should check for port..?

If i am wrong or there is another way from user can be logged out please correct me.


sanjeev
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 04-11-2008, 10:33 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by sanjeevtarar View Post
If i am wrong or there is another way from user can be logged out please correct me.
No Snjeev, I'm not talking about user logged out in the normal way. What I mean there is, if the large number of user are online/available at the same time, there can be a clash in the communicating port. As a result port can be closed. So it can be a real advantage to check the port periodically.

Why I'm asking this is, using Java I never do this. All time I used .Net services fro that. It's so simple.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Logout problem anki1234 JavaServer Pages (JSP) and JSTL 4 01-09-2008 08:54 AM
logout using java script pankajagar2001 JavaServer Pages (JSP) and JSTL 1 01-03-2008 07:37 AM
Need to return to login page once logout peiceonly Suggestions & Feedback 1 08-10-2007 12:18 PM
Sessions and logout question orchid Web Frameworks 1 05-18-2007 07:24 PM


All times are GMT +3. The time now is 07:09 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org