This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes JSP and the fly likes jsp Sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp Sessions" Watch "jsp Sessions" New topic

jsp Sessions

bruno martins

Joined: Oct 28, 2003
Posts: 8
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) {
public void sessionDestroyed(HttpSessionEvent se) {
if(activeSessions > 0)
public static int getActiveSessions() {
return activeSessions;
public void setActiveSessions() {

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

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

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

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

Joined: Jan 10, 2002
Posts: 63334

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: jsp Sessions
It's not a secret anymore!