tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Question about lifetime of HttpServletRequest objects
Date Wed, 18 Oct 2000 23:13:10 GMT
Your approach is not going to work.  You're not allowed to touch the
request object at all, outside of the doGet() or doPost() of the method
that processed that request -- trying to access it later is going to
lead to all sorts of grief.

To track sessions, there are two possible approaches:

* Make sure your application stores a session attribute
  of some particular class in every session as it is created.
  Have this attribute's class implement HttpSessionBindingListener.
  Now, you can tell when sessions are created (valueBound is
  called and when the session expires or times out
  (valueUnbound is called), so you can use this class to
  accumulate a current list of sessions.

* If you're running in a servlet 2.3 container (such as Tomcat 4.0),
  define an application events listener that listens for session
  creation and removal events.

Craig McClanahan

"Ryky.C." wrote:

> Hi,
> I'm trying to implement a session reporting module, of
> which one of the requirements is that it should print
> out the request headers of all the currently active
> sessions. The way I have currently implemented this is
> to maintain a static hashtable which contains
> references to the HttpRequestObject for each incoming
> request, indexed by the JSESSIONID. Each time a
> request comes in, the appropriate entry is updated
> with the new reference. Then in my reporting module, I
> can lookup each request object, and print out the
> various headers and their values.
> The problem is that this approach doesn't seem to
> work. I am only able to print out the details for the
> browser session from which i'm currently logged in,
> and from which i'm trying to print out the various
> session details. i.e, if there are two entries 'Ses1'
> and 'Ses2', and 'Ses2' represents the current browser
> session, then only the request details for 'Ses2' are
> printed out correctly(and completely). when I try to
> print 'Ses1' details, the
> 'HttpServeletRequest.getHeaderNames()' method returns
> an empty Enumeration.
> So my question is:
> is what I am trying to do, possible? is my approach
> incorrect? I guess I could capture the request header
> info each time a request comes in, but I'm afraid that
> will be too much of a performance hit. Ideally, if the
> above approach works, the required data can be
> gathered on a 'as-needed' basis.
> Any help will be very useful.
> thanks,
> ryky.
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Messenger - Talk while you surf!  It's FREE.

See you at ApacheCon Europe <>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat

View raw message