Site icon DataFlair

Advanced Java Project – Product Management System Part – 5

Program 1

<%-- 
    Document   : InsertProduct
    Created on : Nov 6, 2023, 1:22:08 PM
    Author     : admin
--%>

<%@page import="model.Product"%>
<%@page import="dao.ProductDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="header.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% 
           for(int i=1;i<=15;i++)
               out.println("<br>");
        %>
          <center>
             <font color="F19A15" size="7">Update Product By Id</font>
             <br>
             <form method="post" action="UpdateProduct.jsp">
                <table border="1">  
                <tr>
                 <th>Enter Product Id:</th>    
                 <td><input type="text" name="txtid"></td>    
                </tr>   
               <tr>
                   <td></td>
                   <td>
                       <input type="submit" value="Update">
                       <input type="reset" value="Reset">
                   </td>
               </tr>
                </table>      
              </form>    
           <% 
                  
              String prodid=null;
              int pid;
              prodid=request.getParameter("txtid");
             if(prodid!=null) 
             {     
              pid=Integer.parseInt(prodid);
              session.setAttribute("prodid", pid);
              ProductDAO pd=new ProductDAO();
              Product P=null;
              P=pd.searchProduct(pid);
              if(P==null)
                 out.println("<font color=red size=5>Record not found...</font>");
              
              else
              {
               %>
               <font color="red" size="5">Are You Sure want to Update Record</font>
               <table border="1">  
                   <tr>
                       <th>Prod Id</th><th>Prod Name</th><th>Qty</th><th>Amount</th><th>Type</th>
                   </tr>
                  <tr>
                  <form method="post" action="FinalUpdateSave.jsp">
                      <td><%=P.getProdid()%></td>
                      
                      <td><input type="text" name="txtname" value=<%=P.getProdname()%>></td>
                      <td><input type="text" name="txtqty" value=<%=P.getProdqty()%>></td>
                      <td><input type="text" name="txtamt" value=<%=P.getProdamt()%>></td>
                      <td><input type="text" name="txttype" value=<%=P.getProdtype()%>></td>
                      <td><input type="submit" value="Update"></td>    
                      </form>
                  </tr>    
             <%  
              }     
             } 
          %>   
          </table>
          </center>
    </body>
</html>

Program 2

<%-- 
    Document   : FinalUpdateSave
    Created on : Nov 8, 2023, 2:04:39 PM
    Author     : admin
--%>

<%@page import="model.Product"%>
<%@page import="dao.ProductDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="header.jsp"%>
<!DOCTYPE html>
 <% 
           for(int i=1;i<=15;i++)
               out.println("<br>");
        %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
       <center> 
        <%
           int id,qty,amt;
           String name,type;
           id=Integer.parseInt(session.getAttribute("prodid").toString());
           name=request.getParameter("txtname");
           qty=Integer.parseInt(request.getParameter("txtqty"));
           amt=Integer.parseInt(request.getParameter("txtamt"));
           type=request.getParameter("txttype");
           Product P=new Product();
           P.setProdid(id);
           P.setProdname(name);
           P.setProdqty(qty);
           P.setProdamt(amt);
           P.setProdtype(type);
           
           ProductDAO pd=new ProductDAO();
           if(pd.updateProduct(P))
               out.println("<h2>Record updated.................</h2>");
            
        %>
        </center> 
    </body>
</html>
Exit mobile version