aspose file tools*
The moose likes Servlets and the fly likes Session global variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session global variable" Watch "Session global variable" New topic
Author

Session global variable

jeff wisgo
Greenhorn

Joined: Apr 20, 2004
Posts: 15
I am trying to set up code such that when an exception occurs, my custom handler is called which calls a logging class which logs the exception, along with the calling IP [request.getRemoteAddr()]. I thought it would be best to make the logger class static so it could be called easily from anywhere (as opposed to passing an instantiated object into every class I use).
They way I have it coded now, when I initialize the static logger class I pass the calling IP so the logger has that additional information and can write it to the log file. However, I realized this is a bug since that logger class's static variables will be global across all users, in other words if more than person hits the page at a time there will be problems.
I thought that I might need to use S = request.getSession() to store session-scoped variables, but then I have the problem of passing S around to every class that I use in order to get this info.
Does anyone know a good way to do this? I was thinking the best way would be to have a function GetSessionInfo('remoteaddr'), which I can call from anywhere, sort of a session-global variable.
I'm relatively green to Java, so maybe I'm thinking about this the wrong way...
Thanks alot!
[ April 20, 2004: Message edited by: jeff wisgo ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

so maybe I'm thinking about this the wrong way...

I think you are. The purpose of context variables is precisely to contain thread-safe context on behalf of the processing thread. Not wanting to "pass them around" ignores their purpose.
That said, I'd also revisit the decision to make the handler static to begin with. I think that shows that you are not "thinking in Java".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session global variable