Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session global variable

 
jeff wisgo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65226
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic