• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

to find number of user loged in

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to find number of user loged in to my site for that I write a code in which when user loged in it creaete one session for thet user now this session i caught by using HttpSessionListner following is the code
package com;
import java.util.EventListener;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class SessionCounter implements HttpSessionListener{
private static int activeSessions = 0;
public void fireSessionCreatedEvent(HttpSessionEvent se) {
activeSessions++;
}
public void fireSessionDestroyedEvent(HttpSessionEvent se) {
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
}
but here it gives me error
C:\JRun\servlets>javac com/SessionCounter.java
com/SessionCounter.java:5: cannot resolve symbol
symbol : class HttpSessionListener
location: package http
import javax.servlet.http.HttpSessionListener;
^
com/SessionCounter.java:6: cannot resolve symbol
symbol : class HttpSessionEvent
location: package http
import javax.servlet.http.HttpSessionEvent;
^
com/SessionCounter.java:9: cannot resolve symbol
symbol : class HttpSessionListener
location: class com.SessionCounter
public class SessionCounter implements HttpSessionListener{
^
com/SessionCounter.java:13: cannot resolve symbol
symbol : class HttpSessionEvent
location: class com.SessionCounter
public void fireSessionCreatedEvent(HttpSessionEvent se) {
^
com/SessionCounter.java:17: cannot resolve symbol
symbol : class HttpSessionEvent
location: class com.SessionCounter
public void fireSessionDestroyedEvent(HttpSessionEvent se) {
^
my question is why it is not taking "class HttpSessionListener"
is there any method to solve the same problem.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, make sure the jar archive file (i.e. servlet.jar or j2ee.jar) is a part of your classpath.
And also the interface for javax.servlet.http.HttpSessionListener is defined as:

So unless you are planning on labeling your class as Abstract, you must provide implementations for sessionCreated(HttpSessionEvent se) and
sessionDestroyed(HttpSessionEvent se).
I hope this helps.
 
Look ma! I'm selling my stuff!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic