Jsp

Jsp Servlet Sales Project Step by Step

This tutorial will teach you Jsp Servlet Sales Project Step by Step.This project will help you to manage the sales of the shop.

Form Design

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
          <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <form method="get" action="servlet">
                <div class="col-sm-04">
                    <label>Do you Want to Drink</label>
                    <select class="form-control" id="drink" name="drink">
                        <option value="">Please Select Drink</option>
                         <option value="pepsi">Pepsi</option>
                         <option value="cock">Cock</option>
                    </select>
                </div>
                <div class="col-sm-04">
                    <label>Qty</label>
                    <input type="text" name="qty" id="qty" class="form-conrol">
                </div>
                <div class="col-sm-04">
                    <input type="submit" value="Submit" class="btn btn-success">
                </div>
                </form>
            </div>
        </div>
    </body>
</html>

servlet.java

import java.io.IOException;
import java.io.PrintWriter;
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("/servlet")
public class servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
      
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        
        String item = request.getParameter("drink");
        String qty = request.getParameter("qty");
        
        
        int qtty=0;
        int price = 0;
        float discount= 0.0f;
        
        
        if(item.equals("pepsi"))
        {
            price =25;
            discount = 10;
            qtty = Integer.parseInt(qty);
            float amount = qtty * price;
            float disamount = amount * discount/100.0f;
            float bill = amount - disamount;
            
            out.println("<form method='get' action='servlet'>");
            out.println("<table border=2 cellpadding=0 cellspacing=0>");
          
            out.println("<tr>");
             out.println("<td colspan=2>Order Details</td>");
            out.println("</tr>");
            
            out.println("<tr><td>Drink</td> <td> " +  item    +  "</td></tr>");
            out.println("<tr><td>Price</td> <td> " +  price    +  "</td></tr>");
            out.println("<tr><td>Amount</td> <td> " +  amount    +  "</td></tr>");
            out.println("<tr><td>DiscountAmount</td> <td> " +  disamount    +  "</td></tr>");
             out.println("<tr><td>Bill</td> <td> " +  bill    +  "</td></tr>");    
            out.println("</table>");
            out.println("</form>");
            
        }
        else if(item.equals("cock"))
        {
            price =30;
            discount = 5;
            qtty = Integer.parseInt(qty);
            float amount = qtty * price;
            float disamount = amount * discount/100.0f;
            float bill = amount - disamount;
            
            out.println("<form method='get' action='servlet'>");
            out.println("<table border=2 cellpadding=0 cellspacing=0>");
          
            out.println("<tr>");
             out.println("<td colspan=2>Order Details</td>");
            out.println("</tr>");
            
            out.println("<tr><td>Drink</td> <td> " +  item    +  "</td></tr>");
            out.println("<tr><td>Price</td> <td> " +  price    +  "</td></tr>");
            out.println("<tr><td>Amount</td> <td> " +  amount    +  "</td></tr>");
            out.println("<tr><td>DiscountAmount</td> <td> " +  disamount    +  "</td></tr>");
             out.println("<tr><td>Bill</td> <td> " +  bill    +  "</td></tr>");    
            out.println("</table>");
            out.println("</form>");        
        }
    } 
}

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Laravel 11 CRUD Mastering RESTful API MVC with Repository Pattern

In this tutorial will teach Laravel 11 Api MVC with Repository Pattern Crud Application step…

3 weeks ago

Laravel 11 CRUD Application

In this tutorial will teach Laravel 11 CRUD Application step by step. Laravel  11 CRUD…

1 month ago

How to make Times Table in React

in this tutorials we will be talk about how to make a times table in…

2 months ago

Laravel Tutorial: How to Add Numbers Easily Laravel 10

In this tutorials will teach How to add two numbers in Laravel 10. (more…)

2 months ago

Build Full-Stack Node.js MongoDB CRUD App with JWT Authentication

In this tutorial, we will teach the process of building a full-stack application using Node.js,…

3 months ago

Hospital Management System using OOP Java and MySQL

In this tutorial, we will explin you through the process of building a Hospital Management…

3 months ago