I want to save a customers personal information (email, name, phone)
in an HttpSession object so that they don't have to type it in the
next time they come to my page. I'm doing everything in one servlet
(e.g. the servlet generates the form and is also the action for the form).
I use a hidden form variable to know which state I'm in (e.g. should I
print or process the form).
Everything works just fine if the customer doesn't shut down their
browser. In other words, if a customer comes to the form, fills out
their name, submits the form, and then goes back to the form
some time later, their name will be pre-filled. However, if the
customer has shut down their browser at any point, then their
personal information is lost.
Here's the relevant code (using first_name as an example).
=== BEGIN ===
// Get the session. I do this every time and before anything else.
HttpSession the_session = req.getSession(true);
if ( <printing the form>) {
...
// If first_name is non-null, the "first_name" field will be
pre-filled with this value.
String first_name =
(String)the_session.getValue("first_name");
...
}
else { // We must be processing a submitted form
// the_first_name is the value of the "first_name" field or
the empty string.
// Note that I do this before sending output to the client.
the_session.putValue("first_name", the_first_name);
}
=== END ===
Now I've set up my browser (Netscape Communicator 4.51) to warn me when a
server
attempts to write a cookie and my servlet does generate a warning. And I
know that my browser has accepted the cookie because the first_name field
does
get pre-filled when I return. However, when I shut down my browser, it
appears that
no data is ever written to my cookies.txt file and, sure enough, when I
bring up
a new browser, the servlet attempts to write a brand new cookie rather than
grabbing an old one.
What am I doing wrong?
John
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html