0

I am trying to implement multiple submit buttons in a Struts jsp. To do so, I am passing the value of the submit button to the ActionForm and reading that value. My setup is like this:

JSP
...snip...
<form name = "formName" action = "action.do" onSubmit = "return myFunc()" method = "POST">
<input type = "text" name = "myValue" /> 
<input type = "submit" name = "myButton" value = "Submit" />
</form>
...snip...

MyForm
...snip...
String myButton;
String myValue;
[Generated getters and setters]
...snip...

As far as I can tell, the submit button from the jsp should submit a value of 'Submit' to the myButton variable in MyForm, but when I try to access it in the Action Class I always get a value of null.

I know that my struts-config.xml file is configured properly because the text input in the jsp successfully populates the 'myValue' variable in MyForm, which can be read by my Action Class.

Is there something special about submit buttons in Struts that I am missing? It seems everything should work...

Any help would be appreciated.

4

2 回答 2

0

您需要为此使用隐藏的输入类型, value提交按钮的属性仅用于按钮上的文本,而不用于将该值与其余的表单数据一起发送。

于 2013-01-09T02:41:46.963 回答
0

可以通过使用 Struts JSP 标签来定义表单和提交按钮。为什么不使用 Struts JSP 标签?

<html:form action="action.do">
<html:submit property="myButton" value="Submit"/>

希望能帮助到你

于 2013-01-22T08:11:36.697 回答