views:

13

answers:

1

Hello,

I'd like to get/set session parameters within a custom ActionMapper in Struts2. When I call

Map<String, Object> session = ActionContext.getContext().getSession();

within my custom MyActionMapper class, session is null.

What am I doing wrong? Do i have to configure something to actually have a session?

Thanks, Gregor

A: 

This actually works fine as a method within my custom ActionMapper:

private SessionMap<String, Object> getSession(HttpServletRequest request) {
    SessionMap<String, Object> session = 
        (SessionMap<String, Object>) ActionContext.getContext().getSession();

    if ( session == null ) {
        /* create a sessionMap if we don't already have one. */
        session = new SessionMap<String, Object>(request);
    }
    return session;
}
gre

related questions