how can I invalide session while user close browser
I have tried to add onUnload function to javascript, but it seems it doesn't call when user close the browser. Anyone could offer me suggestions?
[153 byte] By [
henry_22a] at [2007-11-27 6:25:05]

# 1
First the core question: why do you want to manually invalidate the session?
# 2
<script language="JavaScript">window.onbeforeunload = confirmExit; function confirmExit() { <%Jsp functionality %>alert("Do you want to close the window");return false; } </script>
# 3
chocolate: so .. you thinks that you can invoke a scriptlet inside a JavaScript function?Go back to the books and try to find out the key difference between serverside and clientside languages.
# 4
Have you tried it to print something like <script language="JavaScript">window.onbeforeunload = confirmExit; function confirmExit() { <%out.println("Inside scripelts")%>} </script>
# 5
Of course .. This is already executed/printed (at the server side) before the JavaScript function is called (at the client side).
# 6
anyway, even IF what you're trying to do there would work (it doesn't) it would still not do what you're trying to achieve as there are ways to close a browser that would not execute any Javascript at all.
# 7
Because my application is only allowed one user is using at one time, if the session is not automatically invalid while user close browser, other user could not log on the application
# 8
You may need to redesign your webapp. For example, invalidate the former sessions on next login only. You can collect sessions using HttpSessionListener.Don't use Javascripts to invoke mandatory serverside actions at all. A client can easily disable/fake/hack clientside languages.
# 9
If anybody got the solution for same query ,plz let me know
# 10
On closing event call jsp page e.g. I ' ve called Logout.jsp
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
window.open('../Jsp/Logout.jsp');
}
</script>
and in Logout.jsp write down your functionality
<%
//
//
session.invalidated();
//
%>
# 11
I would like to submit the url like that : "ReportController?action=logout" in javascript, how can I do that? Because I have implemented a logout menthod for windows onbeforeunload event, which means when user close brower, the logout action will be automatically triggered and submitted to server. I use the below method, but it seems doesn't work.
function logout() {
document.mainform.method="post";
document.mainform.action="ReportController?action=logout";
document.mainform.target="_self";
document.mainform.submit();
}
# 12
the problem with the approach of "onbeforeunload" is that if we navigate within the application also, it will still get invoked and will call the logging out process.
I am facing the same problem, I found solutions such as using frames throughtout the application, but now I cannot embed frames in my application?
can anyone suggest some other solution?