java如何获取复选框选中的值

前台代码:

<form action="" method="get"> 
您喜欢的水果?<br /><br /> 
<label><input name="Fruit" type="checkbox" value="1" />苹果 </label> 
<label><input name="Fruit" type="checkbox" value="2" />桃子 </label> 
<label><input name="Fruit" type="checkbox" value="3" />香蕉 </label> 
<label><input name="Fruit" type="checkbox" value="3" /></label> 
</form> 

后台代码:

public void save(HttpServletRequest request){
        //获取选中的选项
        String[] args=request.getParameterValues("Fruit");
    }

假设四个全选中,则输出:[1,2,3,4];

猜你喜欢

转载自blog.csdn.net/qq_36938933/article/details/79106489