Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

chapter 9 question 11 in Charles Lyon's book

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • 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.

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • 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
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic