0% found this document useful (0 votes)
56 views3 pages

JSP Calculator

The document contains code for a simple calculator web application. It includes an HTML form with fields for two operands and an operator, which submits to a JSP page. The JSP page uses the request parameters to perform the selected operation - addition, subtraction, multiplication or division - on the operands and outputs the result.

Uploaded by

Comas Olivos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views3 pages

JSP Calculator

The document contains code for a simple calculator web application. It includes an HTML form with fields for two operands and an operator, which submits to a JSP page. The JSP page uses the request parameters to perform the selected operation - addition, subtraction, multiplication or division - on the operands and outputs the result.

Uploaded by

Comas Olivos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

AWT pract 4

Cal_form.html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1> CALCULATOR </h1>
<form action="calculate.jsp" method="get">
Operand1: <input type="text" name="op1" value="0" /><br>
Operand2: <input type="text" name="op2" value="0" /><br>
Select operation:
<select name="operator">
<option>+</option>
<option> -</option>
<option> *</option>
<option> /</option>
</select><br>
<input type="submit" value="submit">
</form>
</body>
</html>

Calculate.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
int a,b;
String op;
a=Integer.parseInt(request.getParameter("op1"));
b=Integer.parseInt(request.getParameter("op2"));
op=request.getParameter("operator");
if(op.equals("+"))
out.println("Addition of 2 numbers is: "+(a+b));
else if(op.equals("-"))
out.println("Subtraction of 2 numbers is: "+(a-b));
else if(op.equals("*"))
out.println("Multiplication of 2 numbers is: "+(a*b));
else
out.println("Division of 2 numbers is: "+((double)a/b));
%>
</body>
</html>

Output:

You might also like