File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Cookie Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie Problem" Watch "Cookie Problem" New topic

Cookie Problem

Debajyoti Kundu

Joined: Sep 14, 2011
Posts: 27
Hi Everyone,
I need some help in Cookie. I have created a servlet, where i need to create a cookie which will hold value some of user id which is given in a login page. Code of the login page is not available, only url is known. Along this url a return url is added. After successful validation servlet will redirect to that return url. This login page is invoked from my servlet only.

Can any one suggest a way, by which I can capture the required information in side a Cookie.

N.B: I have tried Cookie[] cookie=request.getCookies(); and it's not working.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Is anything other than your Serlvet accessing this Cookie? What initially created the Cookie?

If you are looking at a pure-servlet solution, look instead at HttpServletRequest.getSession(boolean). This is a higher-level way to create session-persistent data in servlets. The getCookies() method is more low-level, and returns any Cookie data specifically sent from the browser (say if you created a Cookie using JavaScript).

In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Miku Ranjan
Ranch Hand

Joined: Oct 11, 2011
Posts: 98
If you want to store your value in client browser then use cookie.
That should work , the work flow is for the first request the client will not have the value in cookie but after that you will have that value in cookie .
Debajyoti Kundu

Joined: Sep 14, 2011
Posts: 27
Hi Pete, Miku

Thanks for your suggestions. Few days ago I just came to know that value of the cookies were encrypted and the original value can be retrieved after following some formalities.
I agree. Here's the link:
subject: Cookie Problem
It's not a secret anymore!