-->

Struts and Struts-jquery will not work in

2019-08-29 04:14发布

问题:

Do Struts tags <s:submit> and <sj:submit> work on same form? I have already Struts buttons <s:submit>, but now I have added <sj:submit>. So, Struts2-jQuery plugin button is working good, but Struts <s:submit> is not working.

<head>
<sj:head/>
</head>
<s:form id="myForm" action="part!list">
   <s:submit  action="part" method="list" />
</s:form>
<sj:submit targets="result" formId="myform"/>

Please clarify ...

回答1:

<s:submit> works with the form if it's inside the body of the <s:form> or <form> tag. To make it work properly use the action attribute to map the form to the action. You could also use <s:url> to build the url used in the action attribute of the form that correctly builds url even with parameters. But if you map the action in the <s:submit> tag then you have to use only one attribute action or method. These are special parameters used by the action mapper. In the first case form action will be overridden, in the second case the action method overridden. It means that the attributes action and method in the <submit> tag only used to override the default form action mapping. It's rarely used, requires DMI, if you have multiple buttons that have different methods consider to use the method attribute to override the form action mapping.

EDIT:

Example

<head>
   <sj:head/>
</head>
<s:url var="myUrl" action="part" method="list"/>
<s:form id="myForm" action="%{#myUrl}" method="POST">
   <s:submit  action="part2" />
   <s:submit  method="list2" />
   <s:submit />
</s:form>

<sj:submit targets="result" formId="myForm"/>

the above s:submit in the first case use actin named part2 to submit to, the second action name part and method list2, the third is default action name part and method list Ajax calls like the third case.

If your action is mapped on the method list, then you could simplify the url via

<s:url var="myUrl" action="part"/>