hi all,
i looked at 120 first results found on "cookie" search onthe forum, but i still can't find a solution so i'm asking it here :
my servlet tryes to read a cookie containing a user name. if it founds it, the client is redirected; if no cookie has been created, it creates it, verify it has been created, and redirect.
my servlet is on domain ".lionbridge.com", the path is set to "/", IE shows me the cookie, so it's created, but the servlet doesn't find it. the line System.out.println("LIONSSOretrievedValue : " + retrievedValue) displays me : NULL
what's wrong ??
regards,
here is the code :
Best regards,
Elise, XML learning girl X-)
i looked at 120 first results found on "cookie" search onthe forum, but i still can't find a solution so i'm asking it here :
my servlet tryes to read a cookie containing a user name. if it founds it, the client is redirected; if no cookie has been created, it creates it, verify it has been created, and redirect.
my servlet is on domain ".lionbridge.com", the path is set to "/", IE shows me the cookie, so it's created, but the servlet doesn't find it. the line System.out.println("LIONSSOretrievedValue : " + retrievedValue) displays me : NULL
what's wrong ??
regards,
here is the code :
Code:
===================================
retrievedValue = this.getCookie("LionSessId", request);
if (retrievedValue == null)
{
response = this.setCookie("LionSessId", userName, response); //cookie not set ? so let's set it
retrievedValue = this.getCookie(request); //and get back the cookie value
}
if (retrievedValue == userName)
{
response.sendRedirect(wantedURL);
}
System.out.println("LIONSSOretrievedValue : " + retrievedValue);
public HttpServletResponse setCookie(String cookieName, String cookieValue, HttpServletResponse response)
{
LongLivedCookie MyCookie = new LongLivedCookie(cookieName, cookieValue);
MyCookie.setDomain(".lionbridge.com");
MyCookie.setPath("/");
MyCookie.setMaxAge(60*60*24); //24h should be enought
response.addCookie(MyCookie);
return response;
}
public String getCookie(HttpServletRequest request)
{
String Valeur=null;
Cookie[] cookies = request.getCookies();
for(int i=0; i < cookies.length; i++)
{
System.out.println(i);
Cookie thisCookie = cookies[i];
if (thisCookie.getName().equals("LionSessId")) //what i'm looking for
{
Valeur = thisCookie.getValue()
}
else
{
System.out.println("not found");
}
}
return Valeur;
}
===================================
Elise, XML learning girl X-)