简体   繁体   English

Struts-对一个表单使用多个提交按钮? (如何知道单击了哪个)

[英]Struts - Using multiple submit buttons for one form? (How to know which was clicked)

I have 3 buttons for a form I would like to submit. 我要提交的表单有3个按钮。 I'm new to struts and I was wondering, is there a way to find which button was clicked? 我是Struts的新手,我想知道,是否可以找到单击哪个按钮的方法? In my html I have this 在我的HTML中,我有这个

<html:form action="myAction.jspa">
    <div align="right">
        <html:submit value="back" />
        <html:submit value="continue Later" />
        <html:submit value="submit"  />
    </div>
</html:form>

And in my Java Action class in the execute() method, I attempt using request.getParameter("back") to check if the back button has been pressed but it doesn't work. 并且在我的Java Action类中的execute()方法中,我尝试使用request.getParameter("back")来检查是否按下了后退按钮,但它不起作用。 How does one handle multiple submit buttons in struts? 一个如何处理Struts中的多个提交按钮?

Thanks for help in advance :) 预先感谢您的帮助:)

Use the property attribute on your <html:submit> tag to specify the name of the request parameter that you'll check in your action. 使用<html:submit>标记上的property属性来指定将在操作中检查的请求参数的名称。

JSP JSP

<html:submit property="back">back</html:submit>

Action 行动

if(request.getParameter("back") != null) {
    // back button was clicked
}

You can, alternatively, give all of your submit buttons the same property, then check the value of the parameter in your action. 或者,您可以为所有提交按钮赋予相同的属性,然后在操作中检查参数的值。 However, that adds additional internationalization concerns (you'd need to check for non-English translations of the same string). 但是,这增加了其他国际化问题(您需要检查同一字符串的非英语翻译)。

For more information, see the Struts API . 有关更多信息,请参见Struts API

Either use DispatchAction or use javascript and pass value actontype in hidden parameter (back,continue later). 使用DispatchAction或使用javascript并在隐藏参数中传递值actontype(返回,稍后再继续)。

http://unnisworld.wordpress.com/2008/02/14/struts-tip-how-to-organize-related-operations-into-a-single-action-class/ http://unnisworld.wordpress.com/2008/02/14/struts-tip-how-to-organize-related-operations-into-a-single-action-class/

you can get press button id by jquery. 您可以通过jquery获取按钮ID。 Then you know which button has clicked. 然后,您知道单击了哪个按钮。 According to Click button Call struts Action. 根据单击按钮,调用struts动作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM