Use Loop to Read Form Controls : Form Input Data « JSP « Java Tutorial






index.jsp

<HTML>
    <HEAD>
        <TITLE>Submitting Check Boxes</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Submitting Check Boxes</H1>
        <FORM action="basic.jsp" method="post">
            <INPUT TYPE="CHECKBOX" NAME="checks" VALUE="check1" CHECKED>
            Checkbox 1
            <BR>
            <INPUT TYPE="checkbox" NAME="checks" VALUE="check2">
            Checkbox 2
            <BR>
            <INPUT TYPE="checkbox" NAME="checks" VALUE="check3">
            Checkbox 3
            <BR>
            <INPUT TYPE="submit" VALUE="Submit">
        </FORM>
    </BODY>
</HTML>

basic.jsp

<HTML>
    <HEAD>
        <TITLE>Reading Checkboxes</TITLE>
    </HEAD>

    <BODY>
        <H1>Reading Checkboxes</H1>
        You checked: 
        <BR>
        <% String[] items = request.getParameterValues("checks");
        for(int i = 0; i < items.length; i++){
            out.println(items[i] + "<BR>");
        }
        %>
    </BODY>
</HTML>
  Download:  UseLoopToReadFormControls.zip( 1 k)








23.25.Form Input Data
23.25.1.Use Loop to Read Form Controls
23.25.2.Use For Each to Loop Through all Values Passed in by Form
23.25.3.Read Hidden Control in Same File
23.25.4.Pass Form Value to Bean
23.25.5.Form with Error Checking