You must set time-limit for the cookie.
Thanks
----- Original Message -----
From: "Lester June Cabrera" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 29, 2001 9:57 AM
Subject: Can't write cookie
> Hi,
>
> I'm new to JSP. I wrote a sample JSP app that writes/reads cookie. But
> everytime I access the page, it seems that the cookie is not saved because
> when I try to read all the cookies again, I don't see the values I just
> entered. The following is my code. The form calls the same file to submit
> the form.
>
> <%
> // GET Cookies
> Cookie[] cookies = request.getCookies();
>
> if (cookies.length > 0) {
> out.println("Cookies sent from browser:<br>");
> for (int i = 0; i < cookies.length; i++) {
> Cookie cookie = cookies[i];
> out.print("Cookie Name: " + cookie.getName() +
"<br>");
> out.println("Cookie Value: " + cookie.getValue() +
"<br><br>");
> }
> } else {
> out.println("No cookies from browser<br><br>");
> }
>
> // SET Cookies
> String cookieName = request.getParameter("cname");
> String cookieValue = request.getParameter("cvalue");
> if (cookieName != null && cookieValue != null) {
> Cookie cookie = new Cookie(cookieName, cookieValue);
> response.addCookie(cookie);
> out.println("<P>");
> out.println("You just sent the following cookies to your
browser:<br>");
> out.print("Name: " + cookieName + "<br>");
> out.print("Value: " + cookieValue);
> }
>
> %>
>
> <FORM METHOD=POST ACTION="jsp-cookies.jsp">
> <BR>
> Create a cookie to send to your browser:
> <BR>
> Name: <input type=text name="cname" value=""><br>
> Value: <input type=text name="cvalue" value="">
> <br> <INPUT TYPE=submit name=submit Value="Submit">
> <P>
> </FORM>
>
>
>
> Thanks,
> Lester
>
>
>
>
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name
> http://www.jguru.com/jguru/faq/faqpage.jsp?name
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets