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

Creating Grocery Inventory App Using React

Introduction to Grocery Inventory Apps Managing grocery inventory can be a daunting task, but with…

3 hours ago

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app explain…

6 days ago

Fish Inventory Management with React

Introduction to Fish Inventory Management In the aquaculture industry, managing fish inventory is crucial for…

1 week ago

Java GUI CRUD for Beginners

Introduction to Java GUI CRUD Java is a powerful programming language widely used for building…

1 week ago

Creating Beautiful Login Form Design Using React

Introduction to Login Form Design Designing an effective and beautiful login form is crucial for…

2 weeks ago

Creating Responsive Login Form with React

Introduction In today creating a responsive login form is essential for providing a seamless user…

2 weeks ago