I have a simple jsp login page, and I am trying to implement the "remember me2 functionality. The jsp's page code:
String username = "";
Cookie[] vec = request.getCookies();
for(int i=0; vec!=null && i<vec.length; i++)
{
if(vec[i].getName().equals("userNameCookie")&&!vec[i].getValue().equals(""))
{
username = vec[i].getValue();
}
}
The form parameters are sent to the servlet controller, the controller creates the cookie and adds it to the response, and after that the controller forwards the request to the other page.
My issue is that after coming back to the login page the cookie that the controller adds to the response does not exist. In fact, the cookie exists in the page the controller forwarded the request to.
Here's the controller's code:
String username = request.getParameter("username");
String password = request.getParameter("password");
Cookie cookie = new Cookie("userNameCookie", username);
cookie.setMaxAge(7 * 24 * 60 * 60);
response.addCookie(cookie);
getServletConfig().getServletContext().getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response);
What am I doing wrong?
Thanks!