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.
I think the answer lies in the fact that he uses the wordmay.
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).
posted 4 years ago
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?)
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!