Struts2: method attribute in button doesn't work

前端 未结 1 1690
[愿得一人]
[愿得一人] 2020-12-06 02:44

I have a form in jsp. There are two submit buttons: \"Search\" and \"Add New\" button. I had set each button with their own method attribute.



        
相关标签:
1条回答
  • 2020-12-06 03:18

    Set

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    

    to

    <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    

    Another way is to define multiple mappings for the same Action, like

    in JSP:

    <s:submit value="Search"  action="employeeSearchAction" />
    <s:submit value="Add New" action="employeeAddNewAction"/>
    

    in Struts.xml

    <action name="employeeSearchAction" class="example.EmployeeAction" method="doSearch">
           <result>/example/search.jsp</result>
    </action>
    <action name="employeeAddNewAction" class="example.EmployeeAction" method="doAddNew">
           <result>/example/add.jsp</result>
    </action>
    

    A third way is to use Wildcard Mappings.

    P.S: If you go for the second one, I'll suggest, as a best practice, to use one Action for every logical action you have to perform...

    If you have common data loaded / managed by both your actions, "search" and "addNew", then you can define a employeeBaseAction, extended by both employeeSearchAction and employeeAddNewAction.


    EDIT

    It's 2014 now, and DMI usage is unanimously discouraged (today more than ever), other than pretty useless, so I strongly suggest you to use solution n.2.

    0 讨论(0)
提交回复
热议问题