Solved

Best way to write multiple cookies in JSP?

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I clean log of  running tomcat 7 server ? 3 126
How to group array of objects ? 5 65
Can't access image with tomcat/html 6 97
eclipse buid path vs tomcat lib path 10 24
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

822 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