• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

request life span

 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mike. So, the scope of a request ends upon return of the service() method?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic