从复选框中检索多个值

时间:2012-04-19 18:14:29

标签: jsp jdbc struts-1

我希望使用复选框同时使用复选框更新数据库中的多个值。 我正在使用此代码:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link href="../../css/style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <html:form action="viewappnt">
            <table align="left" valign="top" width="295" border="0" id="box-table-b" >
                <thead><tr align="center">
                        <th colspan="4" nowrap><bean:message key="viewapp.heading"/></th>
                    </tr></thead>
                    <%
                        regForm reg = (regForm) session.getAttribute("reg");
                        reg.getspec();
                        String sql = "Select * from appointment where specs=?";
                        ArrayList alist = new ArrayList();
                        alist.add(reg.getSpecs());
                        ResultSet rs = SQLC.getData(sql, alist);
                        int t = 0;
                        while (rs.next()) {
                            String userid = rs.getString("userid");
                            String appdate = rs.getString("appdate");
                            String apptime = rs.getString("apptime");

                    %>
                <td nowrap ><html:text property="appuserid" value="<%=userid%>" size="3" readonly="true" styleId="htmltext"/></td>
                <td width="106"><html:text property="appdate" value="<%=appdate%>" size="5"/></td><td width="80">
                    <html:text property="apptime" value="<%=apptime%>" size="5"/></td>  
                <td><html:checkbox property="apppat"  value="<%=userid%>"></html:checkbox></td>
            </tr> 
            <%
                    t = t++;
                }
            %>
            <tr>
                <td colspan="4" align="center" valign="middle" nowrap><html:submit property="method"><bean:message key="UserForm.apppat"/></html:submit></td>
            </tr>
        </table>
    </html:form>

我没有通过此方法获得如何对多个值使用update命令。

1 个答案:

答案 0 :(得分:0)

public StringBuffer appointPatient() throws ClassNotFoundException, SQLException {
    StringBuffer sb = new StringBuffer();
    String st[] = this.apppat;
    String st1[] = this.appdate;
    String st2[] = this.apptime;
    for (int i = 0; i < st.length; i++) {
        String sql = "update appointment set appdate=? , apptime=?, docuserid=? where userid=? and specs=?";
        ArrayList alist = new ArrayList();
        alist.add(st1[i]);
        alist.add(st2[i]);
        alist.add(this.userid);
        alist.add(st[i]);
        alist.add(this.specs);
        try {
            int rows = SQLC.ins_up_delete(sql, alist);
            if (rows > 0) {
                sb.append("Registration Success");
            }