0

In my struts application, I have 2 namespaces named 'a' and 'b' and defined action 'process' for each namespace.

Now, in some cases I have to chain the request from action 'process' in namespace 'a' to action 'process' in namespace 'b'. However I don't know how to do this in struts.xml. How do I chain these requests to another namespace?

My struts configuration looks like following:

<package name="testa" extends="struts-default, json-default" namespace="/a">
    <action name="process" class="com.khoinguyen.action.ProcessAction" method="handleResponseA">
        <result type="chain" name="return_b">
            <param name="actionName">b/process</param>
        </result>
        <result name="success">completea.jsp</result>
    </action>
</package>
<package name="testb" extends="struts-default, json-default" namespace="/b">
    <action name="process" class="com.khoinguyen.action.ProcessAction" method="handleResponseB">        
        <result name="success">completeb.jsp</result>
    </action>
</package>
Andy
  • 49,085
  • 60
  • 166
  • 233
Khoi Nguyen
  • 1,072
  • 2
  • 15
  • 32

2 Answers2

1

Use <param name="namespace"> inside chain type result. You can see the official documentation about this type result in Struts2 official documentation to see more information about it.

In your case:

<package name="testa" extends="struts-default, json-default" namespace="/a">
    <action name="process" class="com.khoinguyen.action.ProcessAction" method="handleResponseA">
        <result type="chain" name="return_b">
             <param name="namespace">/b</param>
             <param name="actionName">process</param>
        </result>
        <result name="success">completea.jsp</result>
    </action>
</package>
Pigueiras
  • 18,778
  • 10
  • 64
  • 87
  • It works with your suggestion, however in method handleResponseB correspond to action after chained, I cannot get the namespace by method `ServletActionContext.getActionMapping().getNamespace();` It always returns '/', while expectation is '/b' instead of – Khoi Nguyen Dec 12 '12 at 10:57
  • @KhoiNguyen I face to this problem before. Try this: check if the name of the namespace is inside the action name with `ServletActionContext.getActionMapping().getName()`. – Pigueiras Dec 12 '12 at 13:07
  • the name always returns 'process' value due to it's same action name, only namespace is different – Khoi Nguyen Dec 13 '12 at 01:24
0

Please use result type="redirectAction" instead of result type="chain"

Rohit Poudel
  • 1,793
  • 2
  • 20
  • 24