vw729
Mar 28th, 2007, 03:24 PM
Here is my problem occurred in the user sign in logic:
After a correct sign in, the user ID is also stored in a cookie for the future reference in the sign in method of a MultiActionController. Then, it is redirected to another method of the same class to download the user preference data. In this method, I place a segment of code for retrieving all cookies for a testing purpose. It can't find any cookies at all although there are some application cookies such as session ID cookie placed by the Tomcat.
String email = request.getParameter("email");
String password = request.getParameter("password");
User account = service.getAccountByEmailAndPassword(email, password);
if (account != null) {
// ...
Cookie c = new Cookie("user_cookie", userSession.getUser().getId().toString());
c.setMaxAge(86400);
c.setPath("/");
response.addCookie(c);
// ...
}
return new ModelAndView(new RedirectView("/account/home.htm", true));
// ...
And in the following method
logger.debug("");
Cookie[] cookies = request.getCookies();
if (cookies != null) {
logger.debug(cookies.length);
for (int i = 0; i < cookies.length; i++) {
logger.debug("Finding Cookies: " + cookies[i].toString()); // line 1
if (cookies[i].getName().equals("user_cookie")) {
logger.debug("Cookie found: " + cookies[i].toString());
}
}
}
// ...
The line 1 is not reached. In the other words, no cookie is in the request at all. Can anyone explain why the cookie can't be set in the first method and why no cookie is detected in the second method.
Thanks very much for your inputs.
After a correct sign in, the user ID is also stored in a cookie for the future reference in the sign in method of a MultiActionController. Then, it is redirected to another method of the same class to download the user preference data. In this method, I place a segment of code for retrieving all cookies for a testing purpose. It can't find any cookies at all although there are some application cookies such as session ID cookie placed by the Tomcat.
String email = request.getParameter("email");
String password = request.getParameter("password");
User account = service.getAccountByEmailAndPassword(email, password);
if (account != null) {
// ...
Cookie c = new Cookie("user_cookie", userSession.getUser().getId().toString());
c.setMaxAge(86400);
c.setPath("/");
response.addCookie(c);
// ...
}
return new ModelAndView(new RedirectView("/account/home.htm", true));
// ...
And in the following method
logger.debug("");
Cookie[] cookies = request.getCookies();
if (cookies != null) {
logger.debug(cookies.length);
for (int i = 0; i < cookies.length; i++) {
logger.debug("Finding Cookies: " + cookies[i].toString()); // line 1
if (cookies[i].getName().equals("user_cookie")) {
logger.debug("Cookie found: " + cookies[i].toString());
}
}
}
// ...
The line 1 is not reached. In the other words, no cookie is in the request at all. Can anyone explain why the cookie can't be set in the first method and why no cookie is detected in the second method.
Thanks very much for your inputs.