user1884155 user1884155 - 1 month ago 4x
Java Question

Struts2 timing on filling in <s:property> tags in JSP page

I have a simple struts2 web application with one action class and one interceptor. The action class has a getter method

which fetches a string from the session. The interceptor is on the bottom of the default stack so it executes lastly and first after the invocation. It is built in such a way that it can modify the title that is in the session BEFORE action invocation and AFTER invocation. The resulting JSP page then shows this title.

I thought the following logic would apply:

  1. interceptor logic before invocation runs

  2. action class logic runs

  3. interceptor logic after invocation runs

  4. struts knows the result and gets the
    page in the result

  5. struts fills in the
    tags in
    and call
    from the action class.

However this didn't work. The resulting JSP always showed the title as it was before step 3 was executed. I added some simple logging in my java code and it confirmed my suspicion. This was the order of execution:

  1. log: interceptor logic before invocation runs

  2. log: action class logic runs

  3. log:
    method from action class runs

  4. log: interceptor logic after invocation runs

So somehow step 6 became step 3. Why is this and how can I add logic in my interceptor AFTER action invocation to alter the title?


Nutshell: implement PreResultListener to have stuff happen before rendering, but after invocation.

I don't know what title is, but I'm having a hard time understanding why anything relating to something like a page title, or a book title from a domain object, or much else would need to:

  1. Be retrieved by an action, or
  2. Be changed by an interceptor