reading cookies in jsp

Discussion in 'Java' started by ros, Apr 30, 2007.

  1. ros

    ros Guest

    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>
    ros, Apr 30, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,485
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,526
    Fredrik Lindner
    Nov 6, 2003
  3. Replies:
    0
    Views:
    4,357
  4. user
    Replies:
    3
    Views:
    663
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  5. _Who
    Replies:
    7
    Views:
    2,658
Loading...

Share This Page