In JSP, the value submitted by the multiple SELECT statement in the form is obtained. In JSP, the value submitted by the multiple SELECT statement in the form is 10.0102.
Add the multiple = "multiple" attribute to the select tag to convert the drop-down list to the multi-select list ), however, in JSP and Servlet, requests are commonly used to obtain form values. getparameter ("value") obtains only the first selected value in the multiple-choice list. After querying the data, it turns out that httpservletrequest has another method getparametervalues (string Key ), the returned value is a string array, which stores the selected values in the multiple-choice list.
That is to say, the submitted values of the multiple-choice control in the form in JSP and Servlet are obtained through the getparametervalues method, such as the checkbox list (check box list). The sample code is as follows:
<Form action = "index. jsp" method = "Post">
<Select name = "value" multiple = "multiple">
<Option value = "val1"> value 1 </option>
<Option value = "val2"> value 2 </option>
<Option value = "val3"> value 3 </option>
<Option value = "val4"> value 4 </option>
<Option value = "val5"> value 5 </option>
</SELECT>
<Input type = "Submit" value = "Submit">
</Form>
<%
Out. Write ("String [] selected = request. getparametervalues ("value ");
If (selected! = NULL ){
For (INT I = 0; I <selected. length; I ++ ){
Out. Write ("<p>" + selected [I] + "<p> ");
}
} Else {
Out. Write ("<p> no value selected <p> ");
}
%>
1) initial status, not selected
2) Assume that 2, 3, 4 are selected.
3) Result:
4) Select
5) Result: