struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: How to Access an Application Scope object in a Struts Action Clas s
Date Wed, 15 Jan 2003 04:12:59 GMT
 I am working on a similar monitor class to track the users logged into a
web application at any given time. This information is displayed when user
logs into the web application. 

i am trying to accomplish this using ServletContextListener and
HttpSessionAttributeListener classes in the servlet API.

Any help/ideas about tracking users currently logged into a web application
are most welcome.


-----Original Message-----
From: Haseltine, Celeste
To: 'Struts Users Mailing List'
Sent: 1/14/2003 7:41 PM
Subject: How to Access an Application Scope object in a Struts Action Clas s

I'm relatively new to Struts, and I am working in Struts 1.02 (since we
not comfortable using a beta version of struts on a new project), and I
stuck on a simple problem.  If I create a Hashtable bean object called
monitor, with application scope, in my Welcome page using

<jsp:useBean id="monitor" scope="application"

how do I access this application scope object in all of my Struts action
classes?  I've tried using 		Hashtable monitor =
if (monitor != null) {
			-----do something---
and I get a null pointer error, as seen from my error log below:

01/14 18:30:47 error 
	at com.NYTC.struts.LogonAction.perform(

where line 144 is the if (monitor != null) statement.

My objective in using the monitor bean is to keep track of every user
logs in, and if they still have an active session, recover any data and
invalidate the old session, and create a new session for them.  We were
doing this in our previous web apps, but we were using a Model 1
so I am having some trouble converting this concept to a Model 2
In our Model 1 apps, we just used the monitor to keep track of user's
sessions, and invalidate any active session still on server as follows:

if (monitor.containsKey(user)){
	HttpSession oldSession = (HttpSession)monitor.get(user);
	System.out.println("User already has an active session in memory
	---retrieve old data in between here and then invalidate old
	System.out.println("Got rid of the old session");
} else {
	System.out.println("No old session was found");
monitor.put(user, session);

How do I accomplish this using a Model 2 approach??

Thanks in advance for any insight/advice


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message