Thank you, Leon! In essence, you are confirming what I have been doing until now. I don't have a "flag" as such, but it's similar to what you suggest: I basically read the cookies and extract the relevant info that I store in the session --- setAttribute(USER_PREFS, relevantInfoFromCookies).
From then on, for each request, I check the session attribute USER_PREFS:
if not null, use that info; if null, read the cookies instead. I felt this was more redundant than need be, but if there's no shortcut, so be it!
Thanks again! Pierre 2007/1/11, Leon Rosenberg <[EMAIL PROTECTED]>:
It may sound weird, but will do the job perfectly: At first request you read the cookies and put a flag into session, that you already read them: Action (best in a base action of course): execute(HttpServlet req,.... HttpSession session = req.getSession(); if (session.getAttribute(MY_COOKIE_FLAG)==null){ readCookiesAndCustomize(req); session.setAttribute(MY_COOKIE_FLAG,Boolean.TRUE); } regards Leon On 1/11/07, Pierre Thibaudeau <[EMAIL PROTECTED]> wrote: > I would like to read the cookies at the very beginning of a user's session, > in order (for example) to customize the presentation according to his > preferences from his previous sessions. > > I imagine that overriding the sessionCreated() method of an > HttpSessionListener would be ideal for my purpose. The problem is that the > sessionCreated() method provides only an HttpSessionEvent (corresponding to > the creation of the session). What I need is to access an HttpRequest in > order to getCookies(). Surely if the session was created, some HttpRequest > must have been issued in the first place, but how do I get hold of this > request? > > Maybe my problem is that I am not looking at the appropriate Listener. But > I would rather not listen to every single request when I only need to read > cookies once at the beginning of a session! > > Suggestions?