3

I would like to have 2 submit button in my jsp, so I found this tutorial: http://struts.apache.org/release/2.3.x/docs/multiple-submit-buttons.html I want to develop the Nyong Nyong's solution with MyBaseAction class, extended by MySubmitAction and MyClearAction class. But I can't get it work. I'm not sure how the jsp will be, this is in the example:

<s:form method="post" action="mySubmitAction">
    <s:submit value="Submit"/>
    <s:submit value="Clear" action="myClearAction"/>
</form>

But I suppose that it's referred to the previous example. I'm not sure too about the struts.xml, do I need to set some specific constant value or other stuff?

Would be great if somebody could provide a full jsp and struts.xml example.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Accollativo
  • 1,537
  • 4
  • 32
  • 56

2 Answers2

18

If you are using struts in a version newer than 2.3.15.2, you must add this constant to struts.xml to enable the action: prefix:

<constant name="struts.mapper.action.prefix.enabled" value="true" />

because it has been disabled by default.

Read more on Security Bullettin S2-018.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
1

You need to map the "names" of the actions to the actual Action classes you created. If you follow the example and have the struts.xml file like:

<action name="mySubmitAction" class="MySubmitAction">
       <result>submit.jsp</result>
</action>
<action name="myClearAction" class="MyClearAction">
       <result>submit.jsp</result>
</action>

When you click on the input generated by <s:submit value="Submit"/> Struts2 will execute your execute method in your MySubmitAction. When you click on the input generated by <s:submit value="Clear" action="myClearAction"/> struts2 is supposed to override the default action specified by the s:form tag (I haven't tested it) and will execute the execute method in your MyClearAction.

orique
  • 1,295
  • 1
  • 27
  • 36
  • Yes, I know. This is what is written in the guide. But I tried and doesn't work. How will be the jsp? Do I need to add some constant value or other stuff in the struts.xml – Accollativo Feb 06 '14 at 11:29
  • What do you mean by "doesn't work"? Any exception? The second button executes `mySubmitAction`? – orique Feb 06 '14 at 11:32