I am trying to set cookies in a controller servlet before dispatching to a JSP file, but the cookies are not set in the JSP file.
Servlet
Cookie cookie= new Cookie("userName", "wolfmah"
cookie.setMaxAge(60*60*24*7*1);
cookie.setDomain("wolfmahheaven.net"
response.addCookie(cookie);
RequestDispatcher rd= getServletContext().getRequestDispatcher("/cookie1.jsp"
rd.forward(request, response);
JSP (cookie1.jsp)
Cookie[] cookies= request.getCookies();
if (cookies != null) {
for (int i= 0; i < cookies.length; ++i) {
Cookie currentCookie= cookies;
if (currentCookie.getName().equalsIgnoreCase("userName")
out.println(currentCookie.getValue());
else
out.println("null"
}
}
The only output that I get is "null" two times because Tomcat seem to create 2 cookies itself, but mine isn't there.
Servlet
Cookie cookie= new Cookie("userName", "wolfmah"
cookie.setMaxAge(60*60*24*7*1);
cookie.setDomain("wolfmahheaven.net"
response.addCookie(cookie);
RequestDispatcher rd= getServletContext().getRequestDispatcher("/cookie1.jsp"
rd.forward(request, response);
JSP (cookie1.jsp)
Cookie[] cookies= request.getCookies();
if (cookies != null) {
for (int i= 0; i < cookies.length; ++i) {
Cookie currentCookie= cookies;
if (currentCookie.getName().equalsIgnoreCase("userName")
out.println(currentCookie.getValue());
else
out.println("null"
}
}
The only output that I get is "null" two times because Tomcat seem to create 2 cookies itself, but mine isn't there.