Emanuele Mazzante wrote:If a clean all the cookies in the browser and after start my application, that page doesn't show any cookie not even the JSESSIONID cookie.
Client: Hey server, nice place, may I come in?
Server: Sure, welcome. Been here before recently?
Client: Nope, was not here before.
Server: Here is your visitor pass (with some rough details). I call it a cookie which helps me know something about you in your future visit.
Client: Cool then, I will have it with me, bye for now.
<Some unknown time passes>
Client: Hey server, I am back, recognize me?
Server: You have the cookie on you?
Client: Oh yes yes, here.
Server: Ah I see your pass is still valid and you visited some random time ago. Good to have to back.
blah blah blah..
SCJP, SCWCD.
|Asking Good Questions|
Emanuele Mazzante wrote:Could someone be so patience (...and excuse my bad English...) and explain me why this happens?
SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade wrote:
When you first go to the JSP in your browser, there is no cookie created yet for the ${cookie} because the client has not yet sent any cookies to the server and ${cookie} will be evaluated at the server.
The cookies are created on the browser and that is why you can see them using browser tools.
On the form submit or page reload, cookies already created are sent to the server which are reflected in the variable.
To put everything in a dialogue, possible conversation would be as follows.
Amit Ghorpade wrote:In my opinion, Coderanch takes pride in helping folks who want to know and learn, providing appropriate solutions and in a friendly manner.
Amit Ghorpade wrote:
When you first go to the JSP in your browser, there is no cookie created yet for the ${cookie} because the client has not yet sent any cookies to the server and ${cookie} will be evaluated at the server.
The cookies are created on the browser and that is why you can see them using browser tools.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:The server constructs cookies. Some cookies (such as jsessionid) are constructed by the server itself. Some are constructed by the web application program. They are all sent as part of the HTTP Response stream to the client (as part of the headers). The client then caches them and sends them back on the next and subsequent Request(s) - if any. Subject to the constraint that cookies come with an expiration date/time and once that expiration time has passed, the client destroys its copy of the cookie and no longer transmits it.
Tim Holloway wrote:Actually, you've got that backwards. No cookies at all exist when you first direct a browser to a website. How, after all, is the client going to know beforehand what cookies are going to be used? It's not like there's a universal standard.
SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade wrote:I was trying to say the same thing, maybe my construction was poor. The intent was to clarify the fact that ${cookie} is a server side thing and only comes into play when server receives some cookies from the request.
Bear Bibeault wrote:The cookies are created in the browser when the response gets to the browser. A JSP is executed on the server in order to format the response.