?
Solved

Best way to write multiple cookies in JSP?

Posted on 2004-08-16
1
Medium Priority
?
268 Views
Last Modified: 2008-03-06
Hi all,

I have a form that I need to retain specific field information for the customer when they return to use the form multiple times.

I was thinking of writing a cookie to keep the things like 'PHONE', 'EMAIL_ADDRESS', etc. upon execution of the form.  That way I can have the form look for the cookie and pre-populate the field for the customer.

My question is, what is the best way to write this cookie or cookies when one is needing to store multiple field values?  Is there a limit to how many cookies I can write for one form?  Do I write a new cookie for each field?

If I am going about this the wrong way, and there is a better way, then please let me know.

Also, after the cookie is written, do I need to check if the cookie exists, and not write a new one? (I was planning on having the cookie be good for 6 months)

Thanks
0
Comment
Question by:g118481
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
TimYates earned 400 total points
ID: 11809984
<%
       Cookie mycookie = new Cookie("aName","aValue");
       cookie.setMaxAge( timeInSeconds ) ;
       response.addCookie(mycookie);
 %>

> Do I write a new cookie for each field?

I believe so, yes.

> Also, after the cookie is written, do I need to check if the cookie exists, and not write a new one?

You should be able to write a new one, which will overwrite the old one, and set the time back to six months :-)

Tim

PS:  there are 15768000 seconds in 6 montsh (ish) ;-)  

PPS:  I *think* ;-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question