Solved

Best way to write multiple cookies in JSP?

Posted on 2004-08-16
1
261 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
1 Comment
 
LVL 35

Accepted Solution

by:
TimYates earned 100 total points
Comment Utility
<%
       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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now