Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Best way to write multiple cookies in JSP?

Posted on 2004-08-16
1
Medium Priority
?
269 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
Let's take a look into the basics of ransomware—how it spreads, how it can hurt us, and why a disaster recovery plan is important.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

604 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