Andrew Crofts
asked on
Detecting and acting upon a JSP (http) session timeout
I have a web based application using JSPs and Java.
When a user's http session times out I want to detect this and run some logout code.
How do I do this?
TIA
When a user's http session times out I want to detect this and run some logout code.
How do I do this?
TIA
You can use a class that implements
HTTPSessionBindingListener interface. When
session is ending, it will be notified.
Have a look at the HTTPSessionBindingListener API
doc.
HTTPSessionBindingListener
session is ending, it will be notified.
Have a look at the HTTPSessionBindingListener
doc.
ASKER
Any examples?
You need to implement the valueBound and valueUnBound methods in HTTPSessionBindingListener Interface.
import javax.servlet.http.HttpSes sionBindin gListener;
public class MyServlet extends ... implements HttpSessionBindingListener
{
public valueBound(HttpSessionBind ingEvent he)
{
// You are connected to a Session
}
public valueUnbound(HttpSessionBi ndingEvent he)
{
// You are being disconnected from a session
}
Hope that helps!
}
import javax.servlet.http.HttpSes
public class MyServlet extends ... implements HttpSessionBindingListener
{
public valueBound(HttpSessionBind
{
// You are connected to a Session
}
public valueUnbound(HttpSessionBi
{
// You are being disconnected from a session
}
Hope that helps!
}
ASKER
>public class MyServlet extends ... implements HttpSessionBindingListener
{
This seems to imply you are talking about servlets. I am using JSPs and beans. Would the same apply? Could one of my beans implement the HttpSessionBindingListener interface in the same way?
This may be academic as I have found my own method of doing what I want to do. I have added the necessary cleanup code to finalize method of a bean that has session scope. There may be an issue with the timing of when the finalize method get run but I am not sure yet.
{
This seems to imply you are talking about servlets. I am using JSPs and beans. Would the same apply? Could one of my beans implement the HttpSessionBindingListener
This may be academic as I have found my own method of doing what I want to do. I have added the necessary cleanup code to finalize method of a bean that has session scope. There may be an issue with the timing of when the finalize method get run but I am not sure yet.
> Could one of my beans implement the HttpSessionBindingListener interface in the same way?
Yes.
finalize() method is called once by the garbage collector on an object when garbage collection determines that there are no more references to the object. You can put debug statements in the finalize() to see when the finalize() method is called and it is in sync with the session timeout. It will not be prudent to put a code in finalize()that clears up system wide shared resources.
Yes.
finalize() method is called once by the garbage collector on an object when garbage collection determines that there are no more references to the object. You can put debug statements in the finalize() to see when the finalize() method is called and it is in sync with the session timeout. It will not be prudent to put a code in finalize()that clears up system wide shared resources.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello andycrofts,
I have the points on this question to 67. Simply award the question to one of the experts that you want to give points.
The remainder of the 200 points you can use to post dummy questions. Just title them
"Points for <expert ID>".
In the question body, just state:
"For your help with
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20146121 "
Once you've created the dummy question, you should find out what it's URL is. To do that, click on the "Other Questions" link at the top of this page, which brings you to the main page for this topic area. Your new dummy question will be listed at the top. Then, click on the dummy question to find out its URL, which will look a bit like this:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=NAME_OF_TOPIC_AREA_HERE&qid=XXXXXXXXXXX (a number)
Finally, come back to this question and post a comment saying "Posted dummy question for <Expert ID>", you can find it here: <url of dummy question>
Thanks for your cooperation
modder
Community Support
I have the points on this question to 67. Simply award the question to one of the experts that you want to give points.
The remainder of the 200 points you can use to post dummy questions. Just title them
"Points for <expert ID>".
In the question body, just state:
"For your help with
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20146121 "
Once you've created the dummy question, you should find out what it's URL is. To do that, click on the "Other Questions" link at the top of this page, which brings you to the main page for this topic area. Your new dummy question will be listed at the top. Then, click on the dummy question to find out its URL, which will look a bit like this:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=NAME_OF_TOPIC_AREA_HERE&qid=XXXXXXXXXXX (a number)
Finally, come back to this question and post a comment saying "Posted dummy question for <Expert ID>", you can find it here: <url of dummy question>
Thanks for your cooperation
modder
Community Support
ASKER
points for jorj here
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=java&qid=20172820
and sqhosh here
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=java&qid=20172825
Thanks all
Andy
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=java&qid=20172820
and sqhosh here
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=java&qid=20172825
Thanks all
Andy
Or,
Set a java server to listen to a port and handle the sessions by recording them in a vector or something and have them checked from time to time. Then connect to it within the jsp.