Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > setting a cookie in jsp

Thread Tools

setting a cookie in jsp

Posts: n/a

I am trying an exercise on setting cookies. This exercise goes like

"Create a sample home page that accepts a person's name, and birthday
using textfields (use text fields for the name, birth month and birth
day ) and stores that info using a cookie that lasts a year.
Then use the Date and Calendar classes to display a greeting to the
person on his birthday."

I have written the first page that stores the cookies. The relevant
code from this JSP page is as follows -

<H1>What is your Birthday?</H1>

String name = request.getParameter("name");
String month = request.getParameter("month");
String day = request.getParameter("day");

Cookie nameCookie = new Cookie("nameCookie", name);
Cookie monthCookie = new Cookie("monthCookie", month);
Cookie dayCookie = new Cookie("dayCookie", day);



Enter Name: <INPUT TYPE="TEXT" NAME="name">
Enter month of birth: <INPUT TYPE="TEXT" NAME="month">
Enter date of birth: <INPUT TYPE="TEXT" NAME="day">

I have a few questions regarding this code.

1. Is it possible to set 1 cookie instead of 3 cookies as I have done?
2. How should I code the submit button so that it stores the cookie?
Should I give the address of the second page in the ACTION which
confirms submission?

Shall be really thankful for advice and guidance.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP : how can directly get the value of a specified cookie namewithout using a loop FROM the header.cookie ? stunaz Java 2 12-24-2010 03:08 PM
[JSP] difference between jsp:forward and jsp:include Java 0 06-02-2006 01:21 PM
Cookie and Session Cookie Questions. Shapper ASP .Net 1 04-27-2005 11:20 AM
Session cookie? Browser instance cookie? Ben ASP .Net 3 06-03-2004 03:41 AM
IE6 always rejects a particular cookie regardless of privacy/cookie setting Timur Tabi Javascript 1 05-14-2004 09:13 PM