views:

29

answers:

2

I am having problem with session management in struts2. I am setting an attribute in the session in an interceptor which is the default interceptor for my entire application. In my action I am implementing SessionAware interface and grabbing the session as a Map. But the attribute which I set in the interceptor is not present in the session Map I have in my action. Did I miss in any default interceptor in my baseAppStack or any idea what I am missing?

My intercepter definition in struts.xml:

My intercepter code:

    HttpSession session =  request.getSession (true);
 params = (SessionParams)session.getAttribute(Constants.KEY_SESSION_PARAMS);

if (params == null) {

        //some code to populate params

session.setAttribute(Constants.KEY_SESSION_PARAMS, params); }

My Action code:

Map session = getSession();
SessionParams params = (SessionParams) session.get(Constants.KEY_SESSION_PARAMS);
A: 

Interceptor definition is missing my my previous post. Dont know why but I had it when I submitted it.

Interceptor definition:

    <interceptors>
        <interceptor name="baseInterceptor" class="com.interceptors.BaseInterceptor">
        </interceptor>

        <interceptor-stack name="baseAppStack">
            <interceptor-ref name="baseInterceptor" />
            <interceptor-ref name="defaultStack" />
        </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="baseAppStack"></default-interceptor-ref>
chandu
A: 

Sounds ok. Debug your interceptor code (a breakpoint or some log line) to check it is called. And/or copy the full code of your interceptor.

leonbloy

related questions