2中的同一表单上的通常提交

2中的同一表单上的通常提交

本文介绍了JQuery Ajax表单提交以及在Struts 2中的同一表单上的通常提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Struts标签< s:submit> < sj:submit> 是否可以相同的形式工作?我已经有Struts按钮< s:submit> ,但是现在我已经添加了< sj:submit> .

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>.

因此, Struts 2 jQuery插件按钮正常工作,但是Struts < s:submit> 无效.

So, Struts 2 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"/>

推荐答案

< s:submit> 如果该表单位于 < s:form> < form> 标记.为了使其正常工作,请使用 action 属性将表单映射到该动作.您还可以使用 < s:url> 来构建在窗体的 action 属性中使用的url,即使使用参数,该属性也可以正确生成url.但是,如果您在< s:submit> 标记中映射动作,则只需使用一个属性 action method .这些是动作映射器使用的特殊参数.在第一种情况下,将覆盖 action 形式,在第二种情况下,将覆盖action方法.这意味着< submit> 标记中的属性 action method 仅用于覆盖默认的表单动作映射.它很少使用,需要 DMI ,如果您有多个具有不同方法的按钮,请考虑使用 method 属性覆盖表单操作映射.

<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.

示例:

<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"/>

上述 s:submit 在第一种情况下,使用名为 part2 的肌动蛋白进行提交,第二个动作名称 part 和方法 list2 ,第三个是默认操作名称 part 和方法 list Ajax调用类似于第三种情况.

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 listAjax calls like the third case.

如果您的操作映射到方法 list 上,则可以通过以下方式简化网址:

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

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

这篇关于JQuery Ajax表单提交以及在Struts 2中的同一表单上的通常提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:46