I did the same, but extended the request processor, and did all my setup
there. I did this using Struts 1.24, possibly things have changed since
then. That way, each request that came through, I would check for
cookie, and if it did not exist create and move along.
Just throwing out another option.
Scott
-----Original Message-----
From: Pierre Thibaudeau [mailto:pierre.thibaudeau@(protected)]
Sent: Thursday, January 11, 2007 3:01 PM
To: Struts Users Mailing List
Subject: Re: getCookies at beginning of HttpSession
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 <rosenberg.leon@(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 <pierre.thibaudeau@(protected):
> > 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?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)