2 Replies - 204 Views - Last Post: 06 April 2019 - 12:34 PM

#1 alagavat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-March 19

How to retrieve cookies from browser.

Posted 06 April 2019 - 05:57 AM

While I can set cookies named for cookemail,cookpassword and lastly cookrem in the browser, I cannot retrieve them from broswer. I can do all things in localhost side. Normally, these values are retrieved from browser when I run it on the server(tomcat) every time but the server always sees JSESSIONID not see other these values set into the browser.

How can I retrieve them from browser?

Here are the codes shown below.

Setting cookie to the browser
Cookie cEmail = new Cookie("cookemail", email.trim());
                  Cookie cPassword = new Cookie("cookpassword", password.trim());
                  Cookie cRemember = new Cookie("cookrem", remember.trim());
                  cEmail.setMaxAge(60 * 60 * 24 * 15);//15 days
                  cPassword.setMaxAge(60 * 60 * 24 * 15); //15 days
                  cRemember.setMaxAge(60 * 60 * 24 * 15); //15 days
                  response.addCookie(cEmail);
                  response.addCookie(cPassword);
                  response.addCookie(cRemember);


Retrive the cookies from browser (At the end of code snippet -> email = "", password = "",rememberVal="")
Cookie[] cookies = httpRequest.getCookies();

String email = "", password = "",rememberVal="";
            if (cookies != null) {
                 for (Cookie cookie : cookies) {
                   if("cookemail".equals(cookie.getName())) { 
                     email = cookie.getValue();
                   }
                   if("cookpassword".equals(cookie.getName())){ 
                     password = cookie.getValue();
                   }
                   if("cookrem".equals(cookie.getName())){ 
                     rememberVal = cookie.getValue();
                   }
                }
            }
:code:

This post has been edited by modi123_1: 06 April 2019 - 07:08 AM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: How to retrieve cookies from browser.

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15176
  • View blog
  • Posts: 60,744
  • Joined: 12-June 08

Re: How to retrieve cookies from browser.

Posted 06 April 2019 - 07:12 AM

Also seen here:
https://stackoverflo...-browser-in-jsp
https://stackoverflo...-process-in-jsp
Was This Post Helpful? 0
  • +
  • -

#3 alagavat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-March 19

Re: How to retrieve cookies from browser.

Posted 06 April 2019 - 12:34 PM

View Postmodi123_1, on 06 April 2019 - 07:12 AM, said:



These are only mentioned about problem and there is no suggestion or solution from them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1