Accessing the parameters of the result of the stance action in the interceptor

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

actionInvocation.getProxy().getActionName();

      

and the struts action in struts.xml:

<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 in the result tag. Is it possible?

+3


source to share


1 answer


Sure.

You can read the configuration of the result in the ResultConfig object as described here , which will display a map of its parameters as shown in 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>");
}

      

+1


source







All Articles