-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
I want to set cookies at the start of a user's session. From the init method of a class implementing SessionInit, I call the following method:
public static void setCookie(String name, String value, int days) { Cookie cookie = new Cookie(name, value); cookie.setMaxAge(60 * 60 * 24 * days); ((HttpServletResponse) Executions.getCurrent().getNativeResponse()) .addCookie(cookie); }
But I'm getting a NullPointerException at: Executions.getCurrent()....
Is it possible to set cookies from SessionInit?
Thanks,
Richard
You can use DesktopInit instead, and check for the cookie's existence to avoid setting it on every desktop creation. Executions.getCurrent() works in DesktopInit, so your code will work fine.
Since you are probably always creating a desktop when creating a session, it shouldn't matter whether you use SessionInit or DesktopInit.
Asked: 2012-08-14 14:31:01 +0800
Seen: 114 times
Last updated: Aug 15 '12