Discussion:
session listener not listening
Stephen Charles Huey
2004-07-15 23:06:29 UTC
Permalink
My session listener doesn't seem to be listening. At the top of my
web.xml (before any servlet elements, and I have nothing like a filter
or anything else before it), I have this:

<listener>
<listener-class>central.OurSessionListener</listener-class>
</listener>





Here is my listener class:


package central;

import java.util.HashMap;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import wwxchange.utility.*;
import wwxchange.beans.*;

public class OurSessionListener implements HttpSessionListener {

public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
UserAcctBean user = (UserAcctBean)
session.getAttribute("currentuser");
String loginID = user.getLoginID();
System.out.println("Added session: " + session.getId() + " for user
" + user.getLoginID());
SystemControl.addActiveUser(session.getId(), user.getLoginID() );
}

public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
SystemControl.removeActiveUser(session.getId());
System.out.println("Removed session: " + session.getId());
}
}


My SystemControl's static HashMap doesn't seem to be getting updated,
and the above methods aren't even getting called because nothing is
going to stdout when I log in as different users.

What am I doing wrong? Is my listener not registered to listen?

Thanks,
Stephen
Shapira, Yoav
2004-07-16 12:51:47 UTC
Permalink
Hi,
Are you sure that page you are accessing creates a session? ;)

Yoav Shapira
Millennium Research Informatics
-----Original Message-----
Sent: Thursday, July 15, 2004 7:06 PM
To: Tomcat User
Subject: session listener not listening
My session listener doesn't seem to be listening. At the top of my
web.xml (before any servlet elements, and I have nothing like a filter
<listener>
<listener-class>central.OurSessionListener</listener-class>
</listener>
package central;
import java.util.HashMap;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import wwxchange.utility.*;
import wwxchange.beans.*;
public class OurSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
UserAcctBean user = (UserAcctBean)
session.getAttribute("currentuser");
String loginID = user.getLoginID();
System.out.println("Added session: " + session.getId() + " for user
" + user.getLoginID());
SystemControl.addActiveUser(session.getId(), user.getLoginID() );
}
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
SystemControl.removeActiveUser(session.getId());
System.out.println("Removed session: " + session.getId());
}
}
My SystemControl's static HashMap doesn't seem to be getting updated,
and the above methods aren't even getting called because nothing is
going to stdout when I log in as different users.
What am I doing wrong? Is my listener not registered to listen?
Thanks,
Stephen
---------------------------------------------------------------------
This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.
Jarl Skogsholm
2004-07-16 12:59:43 UTC
Permalink
How do I get the user IP address? I only get the IP of the server.

Thanks
--
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety.
-- Benjamin Franklin (1755)
Tim Funk
2004-07-16 13:09:27 UTC
Permalink
HttpServletRequest.getRemoteAddr()

-Tim
Post by Jarl Skogsholm
How do I get the user IP address? I only get the IP of the server.
Thanks
Emerson Cargnin
2004-07-16 16:54:36 UTC
Permalink
if the users are behind a proxy use the following approach:

String endIp = req.getRemoteAddr();
String endIpfoward = req.getHeader("X-Forwarded-For");
//the user is behind a proxy
if (endIpfoward != null) {
endIp = endIpfoward;
}

so you will get the real ip address anyway, even if it's behind a proxy...

Emerson
Post by Tim Funk
HttpServletRequest.getRemoteAddr()
-Tim
Post by Jarl Skogsholm
How do I get the user IP address? I only get the IP of the server.
Thanks
---------------------------------------------------------------------
--
Emerson Cargnin
Analista de Sistemas - Gerente Regional - Tubarão
Setor de Desenvolvimento de Sistemas - TRE-SC
tel : (048) - 251-3700 - Ramal 3181
Stephen Charles Huey
2004-07-16 16:41:53 UTC
Permalink
I'm trying to add this session listener to a production site that often
has over 2,000 concurrent users (according to the Tomcat manager app).
As far as I can tell, a session is created as soon as you log in because
the very first JSP is accessing a bunch of session beans. However, my
listener doesn't seem to be listening!


----- Original message -----
From: "Shapira, Yoav" <***@mpi.com>
To: "Tomcat Users List" <tomcat-***@jakarta.apache.org>
Date: Fri, 16 Jul 2004 08:51:47 -0400
Subject: RE: session listener not listening


Hi,
Are you sure that page you are accessing creates a session? ;)

Yoav Shapira
Millennium Research Informatics
-----Original Message-----
Sent: Thursday, July 15, 2004 7:06 PM
To: Tomcat User
Subject: session listener not listening
My session listener doesn't seem to be listening. At the top of my
web.xml (before any servlet elements, and I have nothing like a filter
<listener>
<listener-class>central.OurSessionListener</listener-class>
</listener>
package central;
import java.util.HashMap;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import wwxchange.utility.*;
import wwxchange.beans.*;
public class OurSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
UserAcctBean user = (UserAcctBean)
session.getAttribute("currentuser");
String loginID = user.getLoginID();
System.out.println("Added session: " + session.getId() + " for user
" + user.getLoginID());
SystemControl.addActiveUser(session.getId(), user.getLoginID() );
}
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
SystemControl.removeActiveUser(session.getId());
System.out.println("Removed session: " + session.getId());
}
}
My SystemControl's static HashMap doesn't seem to be getting updated,
and the above methods aren't even getting called because nothing is
going to stdout when I log in as different users.
What am I doing wrong? Is my listener not registered to listen?
Thanks,
Stephen
---------------------------------------------------------------------
This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential,
proprietary and/or privileged. This e-mail is intended only for the
individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else. If you are not the(an)
intended recipient, please immediately delete this e-mail from your
computer system and notify the sender. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-***@jakarta.apache.org
For additional commands, e-mail: tomcat-user-***@jakarta.apache.org
Stephen Charles Huey
2004-07-16 16:52:10 UTC
Permalink
One other thing: most of our web app's Java classes are put into a
single JAR file in JBuilder that we then dump into Tomcat's common\lib
directory. However, we have to put our servlets individually into
Tomcat's common\classes directory. My session listener class gets
compiled into the JAR file with all of the other classes in that central
package (see below), so I was wondering if perhaps this session listener
class needed to be dropped individually into the same place as where the
servlets go, and I've tried that (I've even tried making sure the class
was also dropped into a directory in common\lib\central in case that's
what it needed). However, this still isn't working for me! At least,
sessionCreated and sessionDestroyed never seem to be called, according
to my print statements (and the static methods they call don't seem to
be updating my session HashMap).


----- Original message -----
From: "Stephen Charles Huey" <***@fastmail.fm>
To: "Tomcat Users List" <tomcat-***@jakarta.apache.org>
Date: Fri, 16 Jul 2004 11:41:53 -0500
Subject: RE: session listener not listening

I'm trying to add this session listener to a production site that often
has over 2,000 concurrent users (according to the Tomcat manager app).
As far as I can tell, a session is created as soon as you log in because
the very first JSP is accessing a bunch of session beans. However, my
listener doesn't seem to be listening!


----- Original message -----
From: "Shapira, Yoav" <***@mpi.com>
To: "Tomcat Users List" <tomcat-***@jakarta.apache.org>
Date: Fri, 16 Jul 2004 08:51:47 -0400
Subject: RE: session listener not listening


Hi,
Are you sure that page you are accessing creates a session? ;)

Yoav Shapira
Millennium Research Informatics
-----Original Message-----
Sent: Thursday, July 15, 2004 7:06 PM
To: Tomcat User
Subject: session listener not listening
My session listener doesn't seem to be listening. At the top of my
web.xml (before any servlet elements, and I have nothing like a filter
<listener>
<listener-class>central.OurSessionListener</listener-class>
</listener>
package central;
import java.util.HashMap;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import wwxchange.utility.*;
import wwxchange.beans.*;
public class OurSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
UserAcctBean user = (UserAcctBean)
session.getAttribute("currentuser");
String loginID = user.getLoginID();
System.out.println("Added session: " + session.getId() + " for user
" + user.getLoginID());
SystemControl.addActiveUser(session.getId(), user.getLoginID() );
}
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
SystemControl.removeActiveUser(session.getId());
System.out.println("Removed session: " + session.getId());
}
}
My SystemControl's static HashMap doesn't seem to be getting updated,
and the above methods aren't even getting called because nothing is
going to stdout when I log in as different users.
What am I doing wrong? Is my listener not registered to listen?
Thanks,
Stephen
---------------------------------------------------------------------
This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential,
proprietary and/or privileged. This e-mail is intended only for the
individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else. If you are not the(an)
intended recipient, please immediately delete this e-mail from your
computer system and notify the sender. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-***@jakarta.apache.org
For additional commands, e-mail: tomcat-user-***@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-***@jakarta.apache.org
For additional commands, e-mail: tomcat-user-***@jakarta.apache.org
Loading...