add and multipy – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Mon, 04 Jul 2022 06:33:50 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg add and multipy – Programmerbay https://programmerbay.com 32 32 Create an application to display addition and product of two numbers on the client side using JSP https://programmerbay.com/create-an-application-to-display-addition-and-product-of-two-numbers-on-the-client-side-using-jsp/ Sat, 07 Dec 2019 15:21:11 +0000 https://programmerbay.com/?p=5667 Simple code to display addition and product of two numbers using JSP.
1) Create a landing page in HTML.
Index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Practical Work</title>
</head>
<body>
<form action="add_multiply.jsp">
<label>First number </label>
 <input type="text" name="num1"/> <br/><br/>
  <label>Second number </label> <input type="text" name="num2"/> <br/><br/> 
  <button type="submit" name="calculate">Product and Sum </button><br/> </form>
</body>
</html>

2) Make a module in JSP that will print the sum and product of two numbers
add_multiply.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter("num2"));
int sum = num1 + num2;
int product = num1 * num2;
out.println("This is the sum = "+sum+"\n This is the product = "+product);
%>
</body>

Output:

Servlet java code to add two numbers 2

]]>