struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "VEDRE, RANAPRATAP REDDY" <VE...@engr.sc.edu>
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.

Thanks,
Rana.




-----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
are
not comfortable using a beta version of struts on a new project), and I
am
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"
class="java.util.Hashtable"/>

how do I access this application scope object in all of my Struts action
classes?  I've tried using 		Hashtable monitor =
(Hashtable)session.getAttribute(Constants.MONITOR_KEY);
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 
java.lang.NullPointerException
	at com.NYTC.struts.LogonAction.perform(LogonAction.java:144)

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

My objective in using the monitor bean is to keep track of every user
who
logs in, and if they still have an active session, recover any data and
then
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
approach,
so I am having some trouble converting this concept to a Model 2
approach.
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
"+
oldSession.getId());
	---retrieve old data in between here and then invalidate old
session------
	oldSession.invalidate();
	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

Celeste




--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message