Foren

Session Destroy event on browser close

Lambert Mickael, geändert vor 11 Jahren.

Session Destroy event on browser close

Junior Member Beiträge: 58 Beitrittsdatum: 29.12.11 Neueste Beiträge
Hello everyone,

I have a problem. Indeed, i created a class which is called on the event : servlet.session.destroy.events

But this class isn't call when we close the navigator before the end of the session (or when we turn off the computer).

Do you know how can I do to call this class whenever the session is destroy (with the navigator close or not) ?

Thanks in advance. I really need help!
Lambert Mickael, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 58 Beitrittsdatum: 29.12.11 Neueste Beiträge
I really need help please. Someone have a solution ?
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
This is a browser thing...

The browser does not notify the server that it is being closed (remember the days way back when the browser just pulled a page from the server and never had to call it again?).

The session destroy will only occur when the session expires due to timeout (inactivity). It is the only way the server knows (guesses) that the user is no longer there.
Lambert Mickael, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 58 Beitrittsdatum: 29.12.11 Neueste Beiträge
David H Nebinger:
This is a browser thing...

The browser does not notify the server that it is being closed (remember the days way back when the browser just pulled a page from the server and never had to call it again?).

The session destroy will only occur when the session expires due to timeout (inactivity). It is the only way the server knows (guesses) that the user is no longer there.


Ok thanks, but when we close the navigator, the session countdown is cancelled ? Because, when i close the navigator and wait the session destroy, my event doesn't occur...

Is there a way to solve that ?
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
There is a javascript-based timer that runs in the browser. It is responsible for showing the 'about to expire' and 'session expired' messages. When the browser is closed, this no longer runs.

So the session stays alive on the server until the session timeout is reached, as defined in your web.xml and/or portal[-ext].properties.

If you enable auto-extend and a short server-side session timeout, the javascript side will keep extending the session automatically. When the browser is closed, the session is not automatically extended and the short server-side timeout will result in the session getting destroyed.
Lambert Mickael, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 58 Beitrittsdatum: 29.12.11 Neueste Beiträge
David H Nebinger:
There is a javascript-based timer that runs in the browser. It is responsible for showing the 'about to expire' and 'session expired' messages. When the browser is closed, this no longer runs.

So the session stays alive on the server until the session timeout is reached, as defined in your web.xml and/or portal[-ext].properties.

If you enable auto-extend and a short server-side session timeout, the javascript side will keep extending the session automatically. When the browser is closed, the session is not automatically extended and the short server-side timeout will result in the session getting destroyed.



Hello, i still have my problem and i think it's really not working.

My class is not called when the session timeout is over and the navigator is close. But it is call when the navigator is open and the session timeout is over.
Rahul Sharma, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 59 Beitrittsdatum: 11.01.12 Neueste Beiträge
Hi Lambert,

May be you can try to destroy cookies by setting setCookie(-1) method in the LoginAction class or by creating hook as setting (-1) will set cookies to destroy the moment browser is closed.
Lambert Mickael, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 58 Beitrittsdatum: 29.12.11 Neueste Beiträge
Rahul Sharma:
Hi Lambert,

May be you can try to destroy cookies by setting setCookie(-1) method in the LoginAction class or by creating hook as setting (-1) will set cookies to destroy the moment browser is closed.


I'm sorry but i don't understand your solution.

Can i put a listener on tomcat otherwise ? A session listener ?
Lambert Mickael, geändert vor 11 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 58 Beitrittsdatum: 29.12.11 Neueste Beiträge
Lambert Mickael:
Rahul Sharma:
Hi Lambert,

May be you can try to destroy cookies by setting setCookie(-1) method in the LoginAction class or by creating hook as setting (-1) will set cookies to destroy the moment browser is closed.


I'm sorry but i don't understand your solution.

Can i put a listener on tomcat otherwise ? A session listener ?


So, can you help me please ? I'm sorry M. Sharma but i really didn't understand what you want me to do.

My point is to delete a row in a database when the session is destroy (the navigator can be open or close) but the event servlet.session.destroy.events isn't call when the navigator is close.

I need help, please.
Rahul Sharma, geändert vor 10 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 59 Beitrittsdatum: 11.01.12 Neueste Beiträge
Sorry for the late reply,but we can use cookies to store data as you are deleting the data,the moment session is expired.As this can be easily done by creating custom hook that reads the liferay default cookies expiry status and at the same time also writes your data in custom cookie.

In my above post I only given you the way to detect that the browser is open or closed as for this you have to create a hook which will continuously work to get the status of the cookie, if that cookie is not available then we can consider that the browser is closed.

Hope that helps!
thumbnail
Rahul Saraswat, geändert vor 10 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 62 Beitrittsdatum: 26.02.13 Neueste Beiträge
Lambert Mickael:
Lambert Mickael:
Rahul Sharma:
Hi Lambert,

May be you can try to destroy cookies by setting setCookie(-1) method in the LoginAction class or by creating hook as setting (-1) will set cookies to destroy the moment browser is closed.


I'm sorry but i don't understand your solution.

Can i put a listener on tomcat otherwise ? A session listener ?


So, can you help me please ? I'm sorry M. Sharma but i really didn't understand what you want me to do.

My point is to delete a row in a database when the session is destroy (the navigator can be open or close) but the event servlet.session.destroy.events isn't call when the navigator is close.

I need help, please.


Hi Lambert Mickael,

Did you found any solution for this? I am also experiencing the same problem since the session time out is not being correcty tracked. If you found any solution for this then please share it. Please find code below which I implemented :

public class BrowserListener implements HttpSessionListener {

private static Log logger = LogFactoryUtil.getLog(BrowserListener.class);

@Override
public void sessionCreated(HttpSessionEvent se) {
logger.info("Session created....");
HttpSession session = se.getSession();
// session.setMaxInactiveInterval(10);
System.out.println("Session id in Listener - " + session.getId());

}

@Override
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
logger.info("Session destroyed...." + session.getId());
}
}
Jai Bharat, geändert vor 9 Jahren.

RE: Session Destroy event on browser close

New Member Beiträge: 3 Beitrittsdatum: 25.06.14 Neueste Beiträge
Dear Rahul Saraswat
How we configure the this listener in liferay
thumbnail
Rahul Saraswat, geändert vor 9 Jahren.

RE: Session Destroy event on browser close

Junior Member Beiträge: 62 Beitrittsdatum: 26.02.13 Neueste Beiträge
Jai Bharat:
Dear Rahul Saraswat
How we configure the this listener in liferay



Hi Jai,

I used polling instead. I sent a request to the client from the server in a specific time frame and checked for some attribute present client side. If it is not present then I assumed that the browser is either closed or inactive for a long time.

Thanks
Rahul Sraswat
Jai Bharat, geändert vor 8 Jahren.

Re: [Liferay Forums][3. Development] RE: Session Destroy event on browser c

New Member Beiträge: 3 Beitrittsdatum: 25.06.14 Neueste Beiträge
Dear
My query is how we stop the concurrent login . when the user login
to One browser and without logout he does not login different browser

On Tue, Dec 2, 2014 at 9:31 PM, Rahul Saraswat from liferay.com <
forums@liferay.com> wrote:

> Jai Bharat:
> Dear Rahul Saraswat
> How we configure the this listener in liferay
>
>
>
> Hi Jai,
>
> I used polling instead. I sent a request to the client from the server in
> a specific time frame and checked for some attribute present client side.
> If it is not present then I assumed that the browser is either closed or
> inactive for a long time.
>
> Thanks
> Rahul Sraswat
>
>
> To view the thread, follow the link below:
>
> https://www.liferay.com/community/forums/-/message_boards/view_message/46111407
> --
> Liferay.com <https://www.liferay.com>
Jai Bharat, geändert vor 8 Jahren.

Re: [Liferay Forums][3. Development] RE: Session Destroy event on browser c

New Member Beiträge: 3 Beitrittsdatum: 25.06.14 Neueste Beiträge
Dear
My query is how we stop the concurrent login . when the user login
to One browser and without logout he does not login different browser

On Tue, Dec 2, 2014 at 9:31 PM, Rahul Saraswat from liferay.com <
forums@liferay.com> wrote:

> Jai Bharat:
> Dear Rahul Saraswat
> How we configure the this listener in liferay
>
>
>
> Hi Jai,
>
> I used polling instead. I sent a request to the client from the server in
> a specific time frame and checked for some attribute present client side.
> If it is not present then I assumed that the browser is either closed or
> inactive for a long time.
>
> Thanks
> Rahul Sraswat
>
>
> To view the thread, follow the link below:
>
> https://www.liferay.com/community/forums/-/message_boards/view_message/46111407
> --
> Liferay.com <https://www.liferay.com>