Solved

Best way to write multiple cookies in JSP?

Posted on 2004-08-16
1
266 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 100 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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