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

ChatGPT Free Online Download the ChatGPT App Easily

Have you ever wanted to talk to a friendly, smart robot that helps you with…

5 days ago

Free GPT Chat? DeepSeek AI Does It Better

DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…

2 weeks ago

Spring Boot MySQL Complete CRUD REST API [ Free Sourecode ]

Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…

3 weeks ago

CREATE Responsive Navigation Bar with FlexBox CSS!

Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…

4 weeks ago

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 months ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

3 months ago