Is it possible to store a cookie to browser from servlet

139 Views Asked by At

Can i store a cookie returned by a REST call to the clients browser. The rest call is made from a jsp page. Ideas or solutions will be helpful. What i need is from abc.com i am calling a webservice of xyz.com which requires authentication. On sucessful authentication xyz.com is returning a cookie and i want to store it in the browser so that if open xyz.com in another tab it should not ask for authentication.

Thanks,

Rahul

1

There are 1 best solutions below

1
On

You can set browser cookie from java servlets - i will suggest make authentication server side, get content and set cookie. (for more detail u can look java doc or tutorial of http response/request)

HttpServletResponse.addHeader("Set-Cookie", "cookie string");

OR

Cookie cookie = new Cookie("name", "value" );
HttpServletResponse.addCookie(cookie);