Table 行数据在 struts 1.2 中提交

Table row data submit in struts 1.2

我有一个 table,每行都包含复选框(如 gmail 收件箱)。我想 select 几个复选框并一次性提交数据 class。 请告诉我如何使用复选框提交表单。

首先,您必须确保您的表单 bean 和您的表单操作 class 已经正常工作,否则即使您准备了 jsp 文件,您也无法检查其正确性(Struts1.2退税)

这是您的 jsp 代码

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<html:html>
    <html:form action="/formAction" method="GET">
        <table>
            <tr>
                <td>Data 1</td>
                <td>
                    <html:checkbox property="chk" value="value1"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>Data 2</td>
                <td>
                    <html:checkbox property="chk" value="value2"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>Data 3</td>
                <td>
                    <html:checkbox property="chk" value="value3"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>Data 4</td>
                <td>
                    <html:checkbox property="chk" value="value4"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>
                    <html:submit value="Register"></html:submit>
                </td>
            </tr>
        </table>
    </html:form>

Form Bean

public class MyFormBean extends ActionForm {
private String chk;
[...]//other fields
public String getChk() {
    return chk;
}

public void setChkString chk) {
    this.chk= chk;
}

[....] // other getters and setters }

动作class的执行方法

[...]
MyFormBean myForm = (MyFormBean) form;
String chkVal = myForm.getChk();
[...]

在 struts-config.xml

中形成 Bean 条目
[...]
<form-bean name="myBean" type="pkg.MyFormBean"/>
[...]

struts-config.xml

中的表单操作条目
[...]
<action path="/formAction" type="pkg.formAction" name="myBean" scope="request">
[...]