Hello everyone, I am a little stuck an this simple task. I have created an html with a form that has 2 user input boxes and 4 button +,-,*,/,. Basically a simple calculator. And I have a jsp to process the form. I am trying to now create a java class to process the 4 methods, then call the class with the jsp through the html. So basically I want my class to do what my jsp is currently doing.
Here is my html code...
<!DOCTYPE HTML>
<html>
<head>
<title>KanJ_calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h3>Justin Calculator</h3>
<a href="index.html">HOME</a><br>
<a href="kanj_oop.html">OOP</a><br /><br />
<form action=kanj_calculator.jsp method="get">
INPUT 1: <input type = "text" name = "input1"><br /><br>
INPUT 2: <input type = "text" name = "input2"><br /><br />
<input type = "submit" name = "btn+" Value = "+" style = "margin-right: 35px">
<input type = "submit" name = "btn-" Value = "-" style = "margin-right: 35px">
<input type = "submit" name = "btn*" Value = "*" style = "margin-right: 35px">
<input type = "submit" name = "btn/" Value = "/">
</form>
</body>
</html>
And here is my current .jsp code...
<!DOCTYPE HTML><%@page language="java"
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Justin kanj_calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h3>Justin kanj_calculator.jsp</h3>
<%
int int1 = (Integer.parseInt(request.getParameter("input1")));
int int2 = (Integer.parseInt(request.getParameter("input2")));
try
{
if (request.getParameter("btn+") != null)
{
out.print("Result = " + (int1 + int2));
}
else if (request.getParameter("btn-") != null)
{
out.print("Result = " + (int1 - int2));
}
else if (request.getParameter("btn*") != null)
{
out.print("Result = " + (int1 * int2));
}
else if (request.getParameter("btn/") != null)
{
out.print("Result = " + (int1 / int2));
}
}
catch (Exception e)
{
out.println("Error! Please enter a valid number: " + e);
}
%>
</body>
</html>
Here is my .java class code so far...which isn't much.
package kanj_unit4;
public class KanJ_Calculator
{
int input1 = 0;
int input2 = 0;
}