Struts - 为一个表单使用多个提交按钮? (如何知道点击了哪个) [英] Struts - Using multiple submit buttons for one form? (How to know which was clicked)

查看:124
本文介绍了Struts - 为一个表单使用多个提交按钮? (如何知道点击了哪个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要提交的表单有3个按钮。我是struts的新手,我想知道,有没有办法找到点击了哪个按钮?在我的HTML中我有这个

I have 3 buttons for a form I would like to submit. I'm new to struts and I was wondering, is there a way to find which button was clicked? In my html I have this

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

在我的Java Action 类中 execute()方法,我尝试使用 request.getParameter(back)检查后退按钮是否已经按下但不起作用。如何处理struts中的多个提交按钮?

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. How does one handle multiple submit buttons in struts?

提前感谢您的帮助:)

推荐答案

使用< html:submit> 标记上的属性属性来指定名称您将在行动中检查的请求参数。

Use the property attribute on your <html:submit> tag to specify the name of the request parameter that you'll check in your action.

JSP

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

行动

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

有关详细信息,请参阅 Struts API

For more information, see the Struts API.

这篇关于Struts - 为一个表单使用多个提交按钮? (如何知道点击了哪个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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