• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp Sessions

 
bruno martins
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i need help this is my code :
package com.stardeveloper.web.listener;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class SessionCounter implements HttpSessionListener {
private static int activeSessions = 0;
public SessionCounter(){
}
public void sessionCreated(HttpSessionEvent se) {
activeSessions++;
}
public void sessionDestroyed(HttpSessionEvent se) {
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
public void setActiveSessions() {
activeSessions--;
}

............
<%-- Sessions.jsp --%>
<%@ page import="com.stardeveloper.web.listener.SessionCounter" %>

<html>
<head>
<title>Active Sessions</title>
</head>
<body>
<p align="center">
<%HSListenerImpl act =new HSListenerImpl();%>

Active Sessions : <%=SessionCounter.getActiveSessions() %>


</p>
</body>
</html>
when i close the browser the session must call the metod sessionDestroyed()
but it not heappen var activeSessions not decrement(--)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to determinstically get notified when the browser is being closed. And you most certainly will not be able to make any server-side requests during the process. You will need to rely upon session timeout to know when the browser has gone away.
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic