Reputation: 21
String userNmae = req.getParameter("userName");
Cookie ck = new Cookie("hello", vall);
res.addCookie(ck);
//lets suppose, I've stored 5 different users name or integer in cookie.
Cookie [] cookies = req.getCookies();
String name;
for(Cookie cookie : cookies) {
name = cookie.getValue();
req.setAttribute("vav", name);
req.getRequestDispatcher("index.jsp").forward(req, res);
}
//Now I would like to retrieve all the values and display on jsp page. How would I do that..
${vav}
jsp file.. Thank you all in advance..
Upvotes: 0
Views: 402
Reputation: 4838
To display cookie value into a JSP, use this code:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:forEach var="cookieVal" items="${pageContext.request.cookies}" >
<tr>
<td align="right">${cookieVal.name}</td>
<td>${cookieVal.value}</td>
</tr>
</c:forEach>
This piece of code was originally taken from this answer.
I hope this helps.
Upvotes: 1