• 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

chapter 9 question 11 in Charles Lyon's book

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

According to Charles Lyon's book, it says line 8 may throw an exception.


If the response has already been committed, the container is using cookie-based tracking, and the session must be created newly; in this case, the container cannot declare the new session with the client, as this involves setting a cookie in the response headers, which cannot happen as the response has been committed.



I have a question about this explanation: "the container cannot declare the new session with the client." But in line 8, the session s can be created if it has not been created before.
As I tried, I don't see any exception happen in line 8.

 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer lies in the fact that he uses the word may.

If the implementation does not throw an exception you might think that it is possible to use the HttpSession object in subsequent requests, but you can't. This is because it involves changing the response headers (to let the client-browser know what the session-id is) which cannot be done at this point (because the response has been commited).
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Frits, thanks for your reply.
I have a question. If the response has been committed, why the HttpSession object cannot be used for subsequent requests?
HttpSession object is used for a sequence of requests.
According to Charles 's book, a client sends the first request within a session.
The servlet responds with a jsessionid. (This response is committed to the client ?)

The client sends a second request within the same session with the jsessionid.
The servlet responds to this request with that jsessionid. (This response is also committed to the client?)
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If the response has been committed, why the HttpSession object cannot be used for subsequent requests?


What I was trying to say is if you create the HttpSession object for the first time at that particular place (where the response has been committed) you won't be able to use the HttpSession object for subsequent requests because there is no way to inform the browser (client).
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic