Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to find number of user loged in

 
Nilesh Chokhadia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic