如何在Struts 2中的一个表单上添加两个提交按钮 [英] How to add two submit buttons on one form in Struts 2

查看:146
本文介绍了如何在Struts 2中的一个表单上添加两个提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Struts2的应用程序。我的应用程序用于在线购物。我的任务是更新并删除购物车项目。我有一个JSP页面,它有4个文本字段。我需要将这些文本字段的数据提交给修改操作。更新和删除提交按钮位于相同的页面中,形式相同。我如何确定我在JSP表单上点击的按钮?

 < s:form action =ModifyCart> 
< s:textfield name =shoppingCart.qtyvalue =%{qty}/>
< s:submit type =buttonlabel =Updatename =submit/>

重要提示:

我需要在每次提交时将所有文本字段的数据提交给 Action 类。

解决方案


如何在struts2中的一个表单中添加2个提交按钮已经完成了, type =button表示一个按钮type =submit是通过Struts标签生成的,但是你可以使用 type =submit 。对于 description 你可以参考文档,它们之间没有太大的区别,因为它们中的任何一个都提交表单。如果你想执行不同的动作或者动作类的方法,那么你可以使用额外的属性如动作方法提交标记中。


我如何确定哪个是屁股我点击了jsp表单


这取决于您希望在客户端还是服务器端执行此操作, 或两者。在客户端,您可以使用JavaScript处理表单或按钮本身的事件。代码由不同的处理程序分隔,因此在处理程序中,您完全知道触发事件的元素,或者使用对象 target 属性来确定类似于这个答案。在服务器端,您可以使用输入按钮属性c $ c>标签,它由 name 生成并作为参数传递。请注意,并非所有HTML浏览器都使用按钮属性。

I'm developing an application using Struts2. My application is for online shopping. My task is updating and removing the shopping cart item. I have a JSP page and it has 4 text fields. I need to submit these text field's data to the Modify action. Updating and removing submit buttons are in same page, same form. How do I determine which is the button I've clicked on JSP form?

My form is:

<s:form action="ModifyCart">
   <s:textfield readonly="true" name="shoppingCart.item.id" label="Item Code" value="% item.id}"/>
   <s:textfield readonly="true" label="Item Name" value="%{item.itemName}"/>
   <s:textfield name="shoppingCart.qty" value="%{qty}"/>                                                                
   <s:textfield readonly="true" label="Available Quantity" name="shoppingCart.item.qty" value="%{item.qty}"/>
   <s:submit type="button" label="Update" name="submit"/>
   <s:submit type="button" label="Remove" name="clear"/></s:form>

Important:

I need to submit all text field's data to the Action class with every submit.

解决方案

How to add 2 submit buttons in one form in struts2

Seems you have already done it, type="button" means a button type="submit" is generated via the Struts tag, but you could use type="submit. For description you can refer the documentation. Not much difference between them, because any of them submit the form. If you want to execute different action or method of the action class then you could use additional attributes like action or method in the submit tag.

How do I determine which is the button I've clicked on jsp form

It depends on where do you want to do it on the client side or on the server side, or both. On the client side you can use javascript to handle events of the form or the button itself. The code is separated by the different handler, so in the handler you exactly know the element that triggered the event, or use an object target attribute to determine that like in this answer. On the server side you can use a value attribute of the input or button tag that is generated and passed as a parameter by name. Note, not all HTML browsers work with the button value attribute.

这篇关于如何在Struts 2中的一个表单上添加两个提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆