?
Solved

java cookies omplementation

Posted on 2004-11-11
7
Medium Priority
?
353 Views
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
0
Comment
Question by:gopal_kgk
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Feldspar
ID: 12562815
cookies are set and read by the web server
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12564420
to go to a URL, just use HTML
<a href='http://mySite.com/server/action?param=1">Go to site</a>

Why do you want to use cookies?

Do you want persistant values sent to that URL?

Give us an example.
0
 

Author Comment

by:gopal_kgk
ID: 12572844
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
0
 

Author Comment

by:gopal_kgk
ID: 12589837
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
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 2000 total points
ID: 12592323
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")) {
        myCookie=cookies[i];
        break;
     }
   }
   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");
  Response.addCookie(myCookie);


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Progress
Introduction to Processes

830 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