Add two numbers using JSP & Servlet

  

ADDITION OF TWO NUMBERS USING JSP & SERVLET

For a complete tutorial on how to add two numbers using JSP & Servlet And How JSP & Servlet works together?

PROGRAM TO ADD TWO NUMBERS USING JSP & SERVLET

SOURCE CODE :

addTwoNumber.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Add Two Number</title>
</head>
<body>
<h1 align="center" style="color:red">ADD TWO NUMBER</h1>

<%
   String result=(String)request.getAttribute("result");
%>

<%
    if(result!=null)
    {
%>
       <h3 align="center" style="color:red">Sum of two number is <span style="color:blue"><%=result %></span></h3>
<%
    }
%>
<div align="center">

<form action="AddNoServlet" method="post">
   <table>
       <tr>
           <td>Enter 1st number: </td>
           <td><input type="text" name="no1"></td>
       </tr>
       
       <tr>
           <td>Enter 2nd number: </td>
           <td><input type="text" name="no2"></td>
       </tr>
       
       <tr>
           <td><input type="submit" value="Add Numbers"></td>
       </tr>
   </table>
</form>

</div>
</body>
</html>

AddNoServlet.java

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AddNoServlet")
public class AddNoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
      
    public AddNoServlet() {
        super();
    }

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Entered into Servlet.");
String number1=request.getParameter("no1");
String number2=request.getParameter("no2");
int no1=Integer.parseInt(number1);
int no2=Integer.parseInt(number2);
int sum=no1+no2;
String result=String.valueOf(sum);
request.setAttribute("result",result);
RequestDispatcher rd=request.getRequestDispatcher("addTwoNumber.jsp");
rd.forward(request, response);
  
}

}


IMAGE REFERENCED IN THE VIDEO FOR EXPLAINING THE CONCEPTS.

Add two numbers using JSP & Servlet

Other practical projects using React & Spring Boot 

1) Employee Management System using Spring Boot Microservices & React.

2) Hotel Management System using Spring Boot & React.

3) E-commerce Project using Spring Boot & React.

4) Gym Management System using Spring Boot & React.

Students can use this project for learning and can submit the project for their final year or Internship projects.

IF YOU WANT THE PROJECT DO CONTACT ME. 

I will give you the full project SOURCE CODE and I will do a COMPLETE SET-UP of the project on your PC or Laptop remotely.

Or You can simply Request for the Project Source Code & Set Up by clicking on the below button.

MAIL ME AT codewithmurad@gmail.com

DM ME ON INSTAGRAM at @codewithmurad

DM ME ON FACEBOOK at @codewithmurad 

DM ME ON TELEGRAM at @codewithmurad 

Connect on My Discord Server: CLICK HERE

Post a Comment

0 Comments