This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes request life span Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "request life span" Watch "request life span" New topic
Author

request life span

Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
Hi, I was wondering about the life time of a HttpServletRequest object. I think it is longer than that of a HttpSession object, since a HttpSession is stored in a HttpServletRequest object. Then when is HttpServletRequest destroyed or expire?
On the same token, how long is the life span of a HttpServletResponse object? When will it expire?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

request and response objects are created by the servlet runner and are provided to servlet coders as parameters on certain (very useful) methods like doGet and doPost. As such (and because the web is stateless) each request and response object are recreated each time the servlet is invoked.

The session is maintained in a different context than these objects, and is only encapsulated by the request object.

I think it's a mistake to link 'containment' with 'life-time'. Just because a request contains a reference to the session, doesn't mean the request lasts longer. In fact, its the opposite.
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
Thank you Mike. So, the scope of a request ends upon return of the service() method?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The scope of the request is over once the particular doXXX method is over.

Request and response objects in servlets are passed as parameters to doXXX methods. Therefore, they are in scope only as long as execution is in those methods.

I should say that the servlet runner may still have these objects after that. They had to come from somewhere right? Somebody passed them to your doXXX method. Maybe they do something to them after the doXXX method is done. I really don't know. But it doesn't matter. As far as you, the servlet writer, is concerned, they are dead after the method ends.
[This message has been edited by Mike Curwen (edited May 29, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request life span
 
Similar Threads
Human Clone and future
session expire exception
Session expire problem with HttpSessionListener
life span of HttpServletRequest and HttpServletResponse
HttpServletRequest Objects