Servlet中怎样获得表单中复选框被选中的值

如题所述

<form action="/ursevlet">

<input type="checkbox" name="fruit" value ="apple">苹果<br>
<input type="checkbox" name="fruit" value ="orange">桔子<br>
<input type="checkbox" name="fruit" value ="mango">芒果<br>

</form>

通过下面得到复选框所选的值
String[] values = request.getParameterValues("fruit") ;
if(values!=null&&values.length>0) {
for(int i= 0 ;i<values.length;i++)
out.println(values[i]) ;
}
温馨提示:答案为网友推荐,仅供参考