1

I have requirement to migrate legacy (Struts 1) code to Struts2.

If there are multiple methods in same action class, can we configure them in single <action> tag?

struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">

<action name="product" 
        class="com.ProductAction"
        method="show">
<result name="success">welcome.jsp</result>
</action>

<action name="product" 
        class="com.ProductAction"
        method="showErr">
<result name="error">error.jsp</result>
</action>

</package>
</struts>    

Here, I have single action i.e. product and single action class i.e. ProductAction. So, can I configure both the methods (show, showErr) in single <action> tag?

Roman C
  • 49,761
  • 33
  • 66
  • 176
AbhiN
  • 642
  • 4
  • 18

1 Answers1

1

The action name is overridden if used in the same package. The action name maps to a specific method or execute.

You can use wildcard mapping to put a method name in the action.

<action name="*product" class="com.ProductAction" method="{1}">
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • in that case, how respective result is bound to the method called. e.g If I have 5 methods in my Action class, I will have to bind 5 results. – AbhiN Jan 25 '18 at 05:11
  • You can use wildcards in the result. See [this](https://stackoverflow.com/a/16531665/573032). – Roman C Jan 30 '18 at 00:19