I am having problem in java to pass cookie from client to server. In java I know a method “setProperty” which pass cookie but it takes parameter “Cookie name” and “Cookie value” separately.But cookies are sent in one string. Is it ok to pass cookie in this process?? Most of the cookies are usually contains not only name , values but also domain and expire date . Is it right to skip those domain and expire date and return the cookie only with name and value ?? I want to log in any cookie site like web browsers.
Share
For a java servlet you use javax.servlet.http.Cookie to create cookies.
Even if the constructor accept name and value parameters that doesn’t mean that those are the only parameters that you can set.
A cookie object has few setters like setDomain or setMaxAge to define your cookie.
(see http://download.oracle.com/javaee/5/api/javax/servlet/http/Cookie.html)
Finally you can add those cookies to the response object.
response.addCookie(c1);
(see http://www.java-tips.org/java-ee-tips/java-servlet/how-to-use-cookies-in-a-servlet.html)