天天看點

jsp中讀取選中的checkbox多選的值

 1.jsp

<form name="form" action="test2.jsp">

<br>

<input TYPE="checkbox" name="fruit" VALUE="apples"> Apples <BR>

<input TYPE="checkbox" name="fruit" VALUE="grapes"> Grapes <BR>

<input TYPE="checkbox" name="fruit" VALUE="oranges"> Oranges <BR>

<input TYPE="checkbox" name="fruit" VALUE="melons"> Melons <BR>

<br>

<input name="aa" type="submit" value="click" />

</form>

2.jsp

<%

String fruit[] =request.getParameterValues("fruit");

for(int i=0;i<fruit.length;i++){

out.println(fruit[i]);

}

%>