|
|
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.
|
|

04-09-2008, 12:52 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
[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
|
|

04-11-2008, 08:07 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
Hi Dear all,
I got the solution itself.
Thanks for your time.
sanjeev
|
|

04-11-2008, 08:13 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Hei Sanjeev Can you please explain how you did it?
|
|

04-11-2008, 08:37 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
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
|
|

04-11-2008, 08:44 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Hei Sanjeev,
My doubt is why are you updating each time the database
when Session Expires? Can You Please Explain?
|
|

04-11-2008, 08:58 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
Not each time dear....just one time from any one of three condition....for particular one user.
sanjeev
|
|

04-11-2008, 08:59 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Ok,
That means you are tracking active users of app and storing to db?
|
|

04-11-2008, 09:03 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
Ya exactly,
we need to track only users who are logged in.
sanejev
|
|

04-11-2008, 09:04 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
OK sanjeev,
Thank you.
|
|

04-11-2008, 09:23 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
|
|
|
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. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 27, 2008)
|
|

04-11-2008, 09:52 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
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
|
|

04-11-2008, 10:33 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
|
|
Originally Posted by sanjeevtarar
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. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 27, 2008)
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|