I have some problems using cookies and sessions in servlets and JSP pages. Can you please show an example about how both of them can be used? I need to create a session or a cookie and use them later, in other pages, but I don't know what methods should be called and in which order. I tried in many ways but I keep getting exceptions. My codes look like...
Cookie score = new Cookie("score", "0");
response.addCookie(score);
HttpSession session = request.getSession();
session.setAttribute("score", new Integer(0));
And in JSP file I try to retrieve them in the following way:
<%>Cookie[] c = request.getCookies();
for(Cookie i : c)
if(i.getName().equals("score"))
System.out.println(i.getValue()); <%>
for cookies and...
<%> System.out.println(request.getAttribute("score")); <%>
for session. But both are null.