1

当然,我如何将多个选中的复选框插入到 Java 中的数据库中。我添加了“,”,但它只存储了第一个选中的复选框。

我该如何解决这个问题?

这是我当前的代码:

String haspaper = null;

if(yes3.isSelected() == true){
    if(checkcontract.isSelected()==true){haspaper=checkcontract.getText()+",";}
    else if(checkcivile.isSelected()==true){haspaper=checkcivile.getText()+" , ";}
    else if(checkcontartpar.isSelected()==true){haspaper=checkcontartpar.getText()+" ,";}
    else {haspaper=mahiyapaper.getText()+" ,";}
}else{haspaper=no3.getText();}
4

3 回答 3

1

您正在为每个 if 条件赋值给haspaper变量。根据您的逻辑附加值,而不是 if else put if block Like :

haspaper += value
于 2013-04-15T13:43:52.130 回答
1

您可以在 servlet/jsp 中捕获检查的值,并将其作为对象存储在 pojo/model 类中,最后使用 jdbc/hibernate 存储到数据库中...

于 2013-04-15T13:44:16.333 回答
1

更正您的代码:

String haspaper="" ;
    if(yes3.isSelected()){
        if(checkcontract.isSelected()){
             haspaper = haspaper + checkcontract.getText()+",";
        }
        else if(checkcivile.isSelected()){
             haspaper = haspaper + checkcivile.getText()+" , ";
        }
        else if(checkcontartpar.isSelected()){
             haspaper = haspaper + checkcontartpar.getText()+" ,";
        }
        else {
             haspaper = haspaper + mahiyapaper.getText()+" ,";
        }
    }else{
         haspaper=no3.getText();
    }
于 2013-04-15T14:00:16.243 回答