java cookies omplementation

Posted on 2004-11-11
Last Modified: 2010-04-17
i need to send url to customers if he clicks it he has to go to that particular url with cookies tell me the exact way i can do along with clear coding
Question by:gopal_kgk
    LVL 1

    Expert Comment

    cookies are set and read by the web server
    LVL 21

    Expert Comment

    to go to a URL, just use HTML
    <a href='">Go to site</a>

    Why do you want to use cookies?

    Do you want persistant values sent to that URL?

    Give us an example.

    Author Comment

    if i create a cookie and seting the cookie if particular cookie value it has to go to onejsp.jsp page if again the user using the same machine he will be going to the same page i need him to go to defaulpage  how how u will remove the existing cookie

    Author Comment

    i have set the cookies and get the cookies value ,but now i need to change the value of the cookies in to new value deleting the existing value in the jsp page how do we cahieve ..can u give code for it clearly
    LVL 21

    Accepted Solution

    You don't need to delete the cookie, just reset the value:

       Cookie[] cookies=request.getCookies();
       Cookie myCookie=null;
       for(int i=0;i<cookies.length;i++) {
         if (cookies[i].getName().equals("MyCookie")) {
       if (myCookie==null) {//cookie not found, must be a new request
         myCookie = new Cookie ("MyCookie", "theCookieValue");
          // Expire in five minutes (5 * 60)
          cookie.setMaxTime( 300 );
          // Expire after the browser is closed
          // cookie.setMaxTime( -1 );

          // Expire right now
          // cookie.setMaxTime( 0 );  //This would delete the cookie)
      myCookie.setValue("New Value");


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now