Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

chapter 9 question 11 in Charles Lyon's book

 
Ranch Foreman
Posts: 1898
12
  • 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.

 
Creator of Enthuware JWS+ V6
Posts: 3343
303
Android Eclipse IDE Chrome
  • 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 Foreman
Posts: 1898
12
  • 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
Posts: 3343
303
Android Eclipse IDE Chrome
  • 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).
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic