reading cookies in jsp

R

ros

Hi,

I am working on this exercise in JSP from SAMS Teach Yourself JSP:

Create a sample page that accepts a person's name and birthday using
text fields for the name, birth month and date and stores this data
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 made the pages for setting the cookie but I am a bit confused
about how to use Date and Calendar for writing the logic for checking
whether the date and month are same as the Systems date and month.

I have attempted this JSP page and it is pasted below.

Can somebody please guide me how to do that? Shall be really grateful.
Cheers.
Ros

<%@ page import="java.util.*" %>

<html>
<head>
<title>Show Saved Cookie</title>
</head>
<body>

<%

GregorianCalendar calendar = new GregorianCalendar();
Date date = new Date();
calendar.setTime(date);

String dateString = new String();
dateString = calendar.get(Calendar.MONTH);

Cookie cookies[] = request.getCookies();

for (int i = 0; i < cookies.length; i++) {

if (cookies.getName().equals("nameCookie")) {
out.println("Hello " + cookies.getValue() +
"<BR>");

}

if (cookies.getName().equals("dayCookie")) {
if (cookies.getValue().equals("17"){
out.println("Date of birth is " + cookies.getValue() +
"<BR>");
}

}

if (cookies.getName().equals("monthCookie")) {
out.println("Month of birth is " + cookies.getValue() +
"<BR>");

}

}

%>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top