Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create an html page that has a form with 2 text inputs, four, submit buttons(

ID: 3811315 • Letter: 1

Question

1. Create an html page that has a form with 2 text inputs, four, submit buttons( for: addition, subtration, multiplication, and division)

2. It calls a JSP to process the form and presents the result in the JSP page.

3. Create a JSP that processes the Form.

Depending on the operator button clicked by user, the JSP should process user inputs, calculate and display the result.

This JSP uses an error page (ANOTHER JSP file) to handle potential exceptions).

o Create the error page for the second JSP. This error page should display a specific message informing users that X and Y must be numbers.

o This error page should call the exception’s getMessage method to display general info of the exception.

o This error page should give users an option to go back to provide correct inputs.

Explanation / Answer

calc.html

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" />
<title>Basic HTML program with external stylesheets</title>
<style type="text/css">
body{background-color: #ffcccc;}
h1{text-align: center;color: #ff0075;}
p{color: #0000ff;}
.main{border: 5px solid #8000ff;padding: 25px;margin-right: 150px; margin-left: 150px;}
  
</style>
</head>
<body>
<h1>Here You can perform basic calculations</h1>
<div class="main">
<form method="get" action="calc.jsp">
<label>Enter your First Number &nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;</label>
<input type="text" name="first" placeholder="Enter ur first number"><br/><br/>
<label>Enter your Second Number : </label>
<input type="text" name="second" placeholder="Enter ur second number"><br/><br/>
<input type="submit" name="add" value="Addition">&nbsp;
<input type="submit" name="sub" value="Subtraction">&nbsp;
<input type="submit" name="mul" value="Multiplication">&nbsp;
<input type="submit" name="div" value="Division"><br/><br/>   
</form>
</div>
</body>
</html

calc.jsp

<html>
<head>
<title>Enter two numbers to add up</title>
</head>
  
<body>
  
<%if(request.getParameter("add")){
int x,y;
x=Integer.parseInt(request.getParameter(“first”));
y=Integer.parseInt(request.getParameter(“second”));
out.print(x+y);

} else if (request.getParameter("sub")) {
int x,y;
x=Integer.parseInt(request.getParameter(“first”));
y=Integer.parseInt(request.getParameter(“second”));
out.print(x-y);
} else if(request.getParameter("mul")){
int x,y;
x=Integer.parseInt(request.getParameter(“first”));
y=Integer.parseInt(request.getParameter(“second”));
out.print(x*y);
} else {
int x,y;
x=Integer.parseInt(request.getParameter(“first”));
y=Integer.parseInt(request.getParameter(“second”));
out.print(x/y);  
}

%>
</body>
</html>