3

I'm using struts and spring integrated frameworks in my project. I have an interceptor before every struts action call. I need to access my action name and am doing so with the following piece of code:

actionInvocation.getProxy().getActionName();

and my struts action in struts.xml is :

<action name="uploadDocument" class="commonAction" method="uploadDocument">
  <interceptor-ref name="sessionStack"/><interceptor-ref name="cachingStack"/>
  <interceptor-ref name="basicStack"/>
  <result name="success" type="stream">
    <param name="contentType">text/html</param>
    <param name="result">inputStream</param>
  </result>
</action>

I need to access the parameters under the result tag. Is that possible?

Roman C
  • 49,761
  • 33
  • 66
  • 176

1 Answers1

1

Sure.

You can read the result configuration in a ResultConfig object, like described here, that will expose a Map of its params, like shown by the source code.

Something like:

// Get the action configuration defined in struts.xml
ActionConfig config = invocation.getProxy().getConfig(); 

// Get the SUCCESS result configured for that Action
ResultConfig success = config.getResults().get("success");

// Iterate the Params, friendly printing :)
for (Map.Entry<String, String> entry : success.getParams().entrySet()) {
    System.out.println("<param name=\"" 
                       + entry.getKey() 
                       + "\">"
                       + entry.getValue()
                       + "</param>");
}
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243