Click to See Complete Forum and Search --> : Java, JSP, & Cookies


rbragg
06-08-2010, 08:41 AM
I am new to all of the above as my language of choice is PHP. I am tinkering with JSF and have a file where I am creating a persistent cookie, tracking how many times a page is visited by a particular user. I want to display the number of hits when the page loads.

This incorrect code is what I have so far for the event-processing:

public void prerender() {
Cookie cookie = new Cookie(hitsResult);
HttpServletResponse response = (HttpServletResponse) getExternalContext().getResponse();
response.addCookie(cookie);
}

... where hitsResult is my JSP component. I'm not even sure if I should be doing it in the prerender method. I'd also like the cookie to expire in a month.

Could anyone direct me?
Thanks!

criterion9
06-08-2010, 10:19 AM
http://www.roseindia.net/jsp/jspcookies.shtml
http://www.roseindia.net/jsp/jspsession/Cookies.shtml
http://www.java-tips.org/java-ee-tips/javaserver-pages/using-cookies-from-jsp.html
http://www.java2s.com/Code/Java/JSP/SettingandReadingCookies.htm