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

Hello chegg experts! I need help creating a java web calculator with JSP and HTM

ID: 3736703 • Letter: H

Question

Hello chegg experts! I need help creating a java web calculator with JSP and HTML requirements in an IDE like Netbeans, and I really need your help! Keep it simple to the requirements, and ignore step 5:

HW4 Web Calculator HTML FORM & JSP (4 points) Instructions: Create a NetBeans Web project to demonstrate the use of HTML Form and JavaServer Pages. You can apply some CSS styles as you see fit. 1 Create an html page1 that functions as the interface of a Web calculator. It should include A heading A form with two text inputs, four submit buttons (representing four math operators), and a reset button that can clear user inputs A table that holds form inputs A that is used to display the result processed by the corresponding JSP for the form Learn the tag from www.w3schools.com or from the Mortgage example posted on Canvas. 2. Create a JSP page that processes the Form in page1. Depending on the operator button clicked by the user, the JSP should process user inputs, calculate and display the result in the iframe at the bottom of page1 as shown in the sample screenshot 1 The JSP should use try and catch blocks to handle potential exceptions. For example, if users leave the fields empty or enter a non-numerical input, an exception will be thrown You should process the exception in the catch block by displaying a specific message informing users that X and Y must be numbers and calling the exception's getMessage method to display general info of the exception (see sample screenshot 2) Next, create an html page2, which is similar to page1 except that it calls a different JSP to process the form and presents the result in the JSP page, not inside the iframe Create a JSP that processes the Form in page2 3. 4. Depending on the operator button clicked by the 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 (sample screenshots 3 and 4) 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. This error page should call the exception's getMessage method to display general info of the exception. This error page should give users an option to go back to provide correct inputs. o o o 5. In one of the html pages, discuss the following: If using JavaScript, what form data of the html page will you verify? Explain in detail Why verifying form data using JavaScript is the preferred approach? Explain in detail

Explanation / Answer

PLEASE REMOVE THE "//" WHEN YOU COPY FIRST TWO QUESTIONS HAVE BEEN MADE SUCCESFFUL AND 4 TH QUESTION JSP PAGES REQUIRE SOME CHANGES CHECK IT AS THEY HAVE SOME ERROR

THE SAME HTML PAGE CAN BE USED BY REMOVING IFRAME AND MODIFYING SUBMIT SOURC LINK.

HTML PAGE:

//<html>
<title>Web Calculator</title>
<head>WEB CALCULATOR</head>
<body>
<form action="CALC.jsp" method="get">
<label for="num1"><b>Number 1</b></lable>
<input type="text" name="num1"><br></br>
<label for="num2"><b>Number 2</b></lable>
<input type="text" name="num2"><br></br>
<input type="submit" name="oper" value="+">
<input type="submit" name="oper"value="-">
<input type="submit" name="oper"value="*">
<input type="submit" name="oper"value="/"></br>
<input type="reset" value="Clear"></br>
<h1>Reslut</h1></br>
<iframe src="calc.jsp">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>

CALC.JSP:

//<html>
<title>calculator</title>
<head>Web Calculator with Exception Handling</head>
<body>
<%@page language="java" %>
<%
int val1;
int val2;
try {
val1 = Integer.parseInt(request.getParameter("num1"));
val2 = Integer.parseInt(request.getParameter("num2"));
String operation = request.getParameter("oper");
if(operation.equals("+")){
int res=val1+val2;
out.println(val1+operation+val2+"="+res);
}
else if(operation.equals("-")){
int res=val1-val2;
out.println(val1+operation+val2+"="+res);
}
else if(operation.equals("*")){
int res=val1*val2;
out.println(val1+operation+val2+"="+res);
}
else if(operation.equals("/")){
int res=val1/val2;
out.println(val1+operation+val2+"="+res);
}
}catch (Exception e) {
out.println("Input error:Please Enter an Integer");
}
%>
</body>
</html>

THESE FOLLOWING JSP PAGES PLEASE VERIFY FOR TRY CATCH STATEMENTS:

JSP1::

<%@ page errorPage = "ShowError.jsp" %>

<html>
<head>
<title>Calculator with Error page</title>
</head>

<body><h1>Calculator with Error page</h1>
<%
int val1;
int val2;
try {
val1 = Integer.parseInt(request.getParameter("num1"));
val2 = Integer.parseInt(request.getParameter("num2"));
String operation = request.getParameter("oper");
if(operation.equals("+")){
int res=val1+val2;
out.println(val1+operation+val2+"="+res);
}
else if(operation.equals("-")){
int res=val1-val2;
out.println(val1+operation+val2+"="+res);
}
else if(operation.equals("*")){
int res=val1*val2;
out.println(val1+operation+val2+"="+res);
}
else if(operation.equals("/")){
int res=val1/val2;
out.println(val1+operation+val2+"="+res);
}
throw new RuntimeException("Error condition!!!");}

  
  

%>
</body>
</html>

JSP2::

<%@ page isErrorPage = "true" %>

<html>
<head>
<title>Error has been occured.</title>
</head>

<body>
<h1>Opps...</h1>
<p>Sorry, an error occurred.</p>
<p>Here is the exception stack trace: </p>
<pre><% exception.printStackTrace(response.getWriter()); %></pre>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote