Form Calculator : Form Post « JSP « Java Tutorial






index.jsp

<HTML>
    <HEAD>
    </HEAD>

    <BODY>
        <FORM ACTION="basic.jsp" METHOD="POST">
            <CENTER>
                <H1>The JSP Calculator</H1>
                <INPUT TYPE="TEXT" NAME="op1" VALUE="">
                <BR>
                +
                <BR>
                <INPUT TYPE="TEXT" NAME="op2" VALUE="">
                <BR>
                <INPUT TYPE="SUBMIT" VALUE="&nbsp;&nbsp;=&nbsp;&nbsp;">
            </CENTER>
        </FORM>
    </BODY>
</HTML>

basic.jsp

<HTML>
    <HEAD>
    </HEAD>

    <BODY>
        <H2>
            <CENTER>
                The sum is:
                <% 
                out.println(Integer.parseInt(request.getParameter("op1")) + 
                    Integer.parseInt(request.getParameter("op2")));
                %>
            </CENTER>
        </H2>
    </BODY>
</HTML>
  Download:  FormCalculator.zip( 1 k)








23.26.Form Post
23.26.1.Get Form Parameter Enumeration
23.26.2.Get Form Parameter By Index
23.26.3.Form Calculator
23.26.4.Process the Form action in the save page
23.26.5.Use multiple forms
23.26.6.Get submit button value