Advertisement
Guest User

cart.jsp

a guest
Dec 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 21.12 KB | None | 0 0
  1. <%--
  2.    Document   : cart
  3.    Created on : Dec 19, 2017, 12:09:06 AM
  4.    Author     : Sam
  5. --%>
  6.  
  7. <%@page import="java.sql.Array"%>
  8. <%@page import="java.sql.ResultSet"%>
  9. <%@page import="java.sql.Statement"%>
  10. <%@page import="java.sql.DriverManager"%>
  11. <%@page import="java.sql.Connection"%>
  12. <%
  13.    String order1 = "";
  14.  
  15.    if (((String) session.getAttribute("order1")) != null) {
  16.        order1 = (String) session.getAttribute("order1");
  17.    }
  18.  
  19.    String qty1 = "";
  20.  
  21.    if (((String) session.getAttribute("qty1")) != null) {
  22.        qty1 = (String) session.getAttribute("qty1");
  23.    }
  24.  
  25.    String order2 = "";
  26.  
  27.    if (((String) session.getAttribute("order2")) != null) {
  28.        order2 = (String) session.getAttribute("order2");
  29.    }
  30.  
  31.    String qty2 = "";
  32.  
  33.    if (((String) session.getAttribute("qty2")) != null) {
  34.        qty2 = (String) session.getAttribute("qty2");
  35.    }
  36.  
  37.    String order3 = "";
  38.  
  39.    if (((String) session.getAttribute("order3")) != null) {
  40.        order3 = (String) session.getAttribute("order3");
  41.    }
  42.  
  43.    String qty3 = "";
  44.  
  45.    if (((String) session.getAttribute("qty3")) != null) {
  46.        qty3 = (String) session.getAttribute("qty3");
  47.    }
  48.  
  49.    String order4 = "";
  50.  
  51.    if (((String) session.getAttribute("order4")) != null) {
  52.        order4 = (String) session.getAttribute("order4");
  53.    }
  54.  
  55.    String qty4 = "";
  56.  
  57.    if (((String) session.getAttribute("qty4")) != null) {
  58.        qty4 = (String) session.getAttribute("qty4");
  59.    }
  60.  
  61.    String order5 = "";
  62.  
  63.    if (((String) session.getAttribute("order5")) != null) {
  64.        order5 = (String) session.getAttribute("order5");
  65.    }
  66.  
  67.    String qty5 = "";
  68.  
  69.    if (((String) session.getAttribute("qty5")) != null) {
  70.        qty5 = (String) session.getAttribute("qty5");
  71.    }
  72.  
  73.    String order6 = "";
  74.  
  75.    if (((String) session.getAttribute("order6")) != null) {
  76.        order6 = (String) session.getAttribute("order6");
  77.    }
  78.  
  79.    String qty6 = "";
  80.  
  81.    if (((String) session.getAttribute("qty6")) != null) {
  82.        qty6 = (String) session.getAttribute("qty6");
  83.    }
  84.  
  85.    String order7 = "";
  86.  
  87.    if (((String) session.getAttribute("order7")) != null) {
  88.        order7 = (String) session.getAttribute("order7");
  89.    }
  90.  
  91.    String qty7 = "";
  92.  
  93.    if (((String) session.getAttribute("qty7")) != null) {
  94.        qty7 = (String) session.getAttribute("qty7");
  95.    }
  96.  
  97.    String order8 = "";
  98.  
  99.    if (((String) session.getAttribute("order8")) != null) {
  100.        order8 = (String) session.getAttribute("order8");
  101.    }
  102.  
  103.    String qty8 = "";
  104.  
  105.    if (((String) session.getAttribute("qty8")) != null) {
  106.        qty8 = (String) session.getAttribute("qty8");
  107.    }
  108.  
  109.    String order9 = "";
  110.  
  111.    if (((String) session.getAttribute("order9")) != null) {
  112.        order9 = (String) session.getAttribute("order9");
  113.    }
  114.  
  115.    String qty9 = "";
  116.  
  117.    if (((String) session.getAttribute("qty9")) != null) {
  118.        qty9 = (String) session.getAttribute("qty9");
  119.    }
  120.  
  121.    String order10 = "";
  122.  
  123.    if (((String) session.getAttribute("order10")) != null) {
  124.        order10 = (String) session.getAttribute("order10");
  125.    }
  126.  
  127.    String qty10 = "";
  128.  
  129.    if (((String) session.getAttribute("qty10")) != null) {
  130.        qty10 = (String) session.getAttribute("qty10");
  131.    }
  132.  
  133.    double subtotal1 = 0.0;
  134.    double subtotal2 = 0.0;
  135.    double subtotal3 = 0.0;
  136.    double subtotal4 = 0.0;
  137.    double subtotal5 = 0.0;
  138.    double subtotal6 = 0.0;
  139.    double subtotal7 = 0.0;
  140.    double subtotal8 = 0.0;
  141.    double subtotal9 = 0.0;
  142.    double subtotal10 = 0.0;
  143. %>
  144.  
  145. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  146. <!DOCTYPE html>
  147. <html>
  148.     <head>
  149.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  150.         <title>Order Cart</title>
  151.     </head>
  152.     <body>
  153.         <h1>Order Cart</h1>
  154.  
  155.         <table border="1">
  156.             <thead>
  157.             <td>
  158.                 Order Items
  159.             </td>
  160.             <td>
  161.                 No. Item
  162.             </td>
  163.             <td>
  164.                 Subtotal
  165.             </td>
  166.             <td>
  167.                 </thead>
  168.             </td>
  169.  
  170.             <%                Connection connection = null;
  171.  
  172.                try {
  173.                    Class.forName("org.gjt.mm.mysql.Driver");
  174.                    String url = "jdbc:mysql://localhost/dbburgenator";
  175.                    String user = "root";
  176.                    String pwd = "";
  177.                    connection = DriverManager.getConnection(url, user, pwd);
  178.                    Statement statement = null;
  179.                    ResultSet resultSet = null;
  180.                    statement = connection.createStatement();
  181.  
  182.                    String sql = "select * from product";
  183.                    resultSet = statement.executeQuery(sql);
  184.                    while (resultSet.next()) {
  185.                        //start one product
  186.                        if ((order1.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order1")) != null) && (((String) session.getAttribute("qty1")) != null)) {
  187.            %>
  188.  
  189.             <tr>
  190.                 <td>
  191.                     <%=resultSet.getString("productName")%>
  192.                 </td>
  193.                 <td>
  194.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  195.  
  196.                         <input type='text' name='qty1' id='qty1' value="<%=qty1%>" size="1" />
  197.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty1").value++;' value='+'/>
  198.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty1").value--;' value='-'/>
  199.                 </td>    
  200.                 <td>
  201.                     <%
  202.                        int Iqty = Integer.parseInt(qty1);
  203.                        double price = resultSet.getDouble("productPrice");
  204.                        subtotal1 = 0.0;
  205.                        subtotal1 = Iqty * price;
  206.                        out.println("RM" + subtotal1);
  207.                    %>
  208.                 </td>
  209.                 <td>
  210.                     <input type="hidden" name="order1" value="<%=order1%>">
  211.                     <input type="submit" value="Update Order">
  212.                     </form>
  213.  
  214.                 </td>
  215.             </tr>
  216.             <%
  217.                }
  218.                //end one product
  219.                //start one product
  220.                if ((order2.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order2")) != null) && (((String) session.getAttribute("qty2")) != null)) {
  221.            %>
  222.  
  223.             <tr>
  224.                 <td>
  225.                     <%=resultSet.getString("productName")%>
  226.                 </td>
  227.                 <td>
  228.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  229.                         <input type='text' name='qty2' id='qty2' value="<%=qty2%>" size="1" />
  230.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty2").value++;' value='+'/>
  231.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty2").value--;' value='-'/>
  232.                 </td>    
  233.                 <td>
  234.                     <%
  235.                        int Iqty = Integer.parseInt(qty2);
  236.                        double price = resultSet.getDouble("productPrice");
  237.                        subtotal2 = 0.0;
  238.                        subtotal2 = Iqty * price;
  239.                        out.println("RM" + subtotal2);
  240.                    %>
  241.                 </td>
  242.                 <td>
  243.                     <input type="hidden" name="order2" value="<%=order2%>">
  244.                     <input type="submit" value="Update Order">
  245.                     </form>
  246.  
  247.                 </td>
  248.             </tr>
  249.             <%
  250.                }
  251.                //end one product
  252.                //start one product
  253.                if ((order3.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order3")) != null) && (((String) session.getAttribute("qty3")) != null)) {
  254.            %>
  255.  
  256.             <tr>
  257.                 <td>
  258.                     <%=resultSet.getString("productName")%>
  259.                 </td>
  260.                 <td>
  261.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  262.                         <input type='text' name='qty3' id='qty3' value="<%=qty3%>" size="1" />
  263.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty3").value++;' value='+'/>
  264.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty3").value--;' value='-'/>
  265.                 </td>    
  266.                 <td>
  267.                     <%
  268.                        int Iqty = Integer.parseInt(qty3);
  269.                        double price = resultSet.getDouble("productPrice");
  270.                        subtotal3 = 0.0;
  271.                        subtotal3 = Iqty * price;
  272.                        out.println("RM" + subtotal3);
  273.                    %>
  274.                 </td>
  275.                 <td>
  276.                     <input type="hidden" name="order3" value="<%=order3%>">
  277.                     <input type="submit" value="Update Order">
  278.                     </form>
  279.  
  280.                 </td>
  281.             </tr>
  282.             <%
  283.                }
  284.                //end one product
  285.                //start one product
  286.                if ((order4.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order4")) != null) && (((String) session.getAttribute("qty4")) != null)) {
  287.            %>
  288.  
  289.             <tr>
  290.                 <td>
  291.                     <%=resultSet.getString("productName")%>
  292.                 </td>
  293.                 <td>
  294.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  295.                         <input type='text' name='qty4' id='qty4' value="<%=qty4%>" size="1" />
  296.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty4").value++;' value='+'/>
  297.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty4").value--;' value='-'/>
  298.                 </td>    
  299.                 <td>
  300.                     <%
  301.                        int Iqty = Integer.parseInt(qty4);
  302.                        double price = resultSet.getDouble("productPrice");
  303.                        subtotal4 = 0.0;
  304.                        subtotal4 = Iqty * price;
  305.                        out.println("RM" + subtotal4);
  306.                    %>
  307.                 </td>
  308.                 <td>
  309.                     <input type="hidden" name="order4" value="<%=order4%>">
  310.                     <input type="submit" value="Update Order">
  311.                     </form>
  312.  
  313.                 </td>
  314.             </tr>
  315.             <%
  316.                }
  317.                //end one product
  318.                //start one product
  319.                if ((order5.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order5")) != null) && (((String) session.getAttribute("qty5")) != null)) {
  320.            %>
  321.  
  322.             <tr>
  323.                 <td>
  324.                     <%=resultSet.getString("productName")%>
  325.                 </td>
  326.                 <td>
  327.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  328.                         <input type='text' name='qty5' id='qty5' value="<%=qty5%>" size="1" />
  329.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty5").value++;' value='+'/>
  330.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty5").value--;' value='-'/>
  331.                 </td>    
  332.                 <td>
  333.                     <%
  334.                        int Iqty = Integer.parseInt(qty5);
  335.                        double price = resultSet.getDouble("productPrice");
  336.                        subtotal5 = 0.0;
  337.                        subtotal5 = Iqty * price;
  338.                        out.println("RM" + subtotal5);
  339.                    %>
  340.                 </td>
  341.                 <td>
  342.                     <input type="hidden" name="order5" value="<%=order5%>">
  343.                     <input type="submit" value="Update Order">
  344.                     </form>
  345.  
  346.                 </td>
  347.             </tr>
  348.             <%
  349.                }
  350.                //end one product
  351.                //start one product
  352.                if ((order6.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order6")) != null) && (((String) session.getAttribute("qty6")) != null)) {
  353.            %>
  354.  
  355.             <tr>
  356.                 <td>
  357.                     <%=resultSet.getString("productName")%>
  358.                 </td>
  359.                 <td>
  360.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  361.                         <input type='text' name='qty6' id='qty6' value="<%=qty6%>" size="1" />
  362.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty6").value++;' value='+'/>
  363.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty6").value--;' value='-'/>
  364.                 </td>    
  365.                 <td>
  366.                     <%
  367.                        int Iqty = Integer.parseInt(qty6);
  368.                        double price = resultSet.getDouble("productPrice");
  369.                        subtotal6 = 0.0;
  370.                        subtotal6 = Iqty * price;
  371.                        out.println("RM" + subtotal6);
  372.                    %>
  373.                 </td>
  374.                 <td>
  375.                     <input type="hidden" name="order6" value="<%=order6%>">
  376.                     <input type="submit" value="Update Order">
  377.                     </form>
  378.  
  379.                 </td>
  380.             </tr>
  381.             <%
  382.                }
  383.                //end one product
  384.                //start one product
  385.                if ((order7.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order7")) != null) && (((String) session.getAttribute("qty7")) != null)) {
  386.            %>
  387.  
  388.             <tr>
  389.                 <td>
  390.                     <%=resultSet.getString("productName")%>
  391.                 </td>
  392.                 <td>
  393.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  394.                         <input type='text' name='qty7' id='qty7' value="<%=qty7%>" size="1" />
  395.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty7").value++;' value='+'/>
  396.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty7").value--;' value='-'/>
  397.                 </td>    
  398.                 <td>
  399.                     <%
  400.                        int Iqty = Integer.parseInt(qty7);
  401.                        double price = resultSet.getDouble("productPrice");
  402.                        subtotal7 = 0.0;
  403.                        subtotal7 = Iqty * price;
  404.                        out.println("RM" + subtotal7);
  405.                    %>
  406.                 </td>
  407.                 <td>
  408.                     <input type="hidden" name="order7" value="<%=order7%>">
  409.                     <input type="submit" value="Update Order">
  410.                     </form>
  411.  
  412.                 </td>
  413.             </tr>
  414.             <%
  415.                }
  416.                //end one product
  417.                //start one product
  418.                if ((order8.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order8")) != null) && (((String) session.getAttribute("qty8")) != null)) {
  419.            %>
  420.  
  421.             <tr>
  422.                 <td>
  423.                     <%=resultSet.getString("productName")%>
  424.                 </td>
  425.                 <td>
  426.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  427.                         <input type='text' name='qty8' id='qty8' value="<%=qty8%>" size="1" />
  428.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty8").value++;' value='+'/>
  429.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty8").value--;' value='-'/>
  430.                 </td>    
  431.                 <td>
  432.                     <%
  433.                        int Iqty = Integer.parseInt(qty8);
  434.                        double price = resultSet.getDouble("productPrice");
  435.                        subtotal8 = 0.0;
  436.                        subtotal8 = Iqty * price;
  437.                        out.println("RM" + subtotal8);
  438.                    %>
  439.                 </td>
  440.                 <td>
  441.                     <input type="hidden" name="order8" value="<%=order8%>">
  442.                     <input type="submit" value="Update Order">
  443.                     </form>
  444.  
  445.                 </td>
  446.             </tr>
  447.             <%
  448.                }
  449.                //end one product
  450.                //start one product
  451.                if ((order9.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order9")) != null) && (((String) session.getAttribute("qty9")) != null)) {
  452.            %>
  453.  
  454.             <tr>
  455.                 <td>
  456.                     <%=resultSet.getString("productName")%>
  457.                 </td>
  458.                 <td>
  459.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  460.                         <input type='text' name='qty9' id='qty9' value="<%=qty9%>" size="1" />
  461.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty9").value++;' value='+'/>
  462.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty9").value--;' value='-'/>
  463.                 </td>    
  464.                 <td>
  465.                     <%
  466.                        int Iqty = Integer.parseInt(qty9);
  467.                        double price = resultSet.getDouble("productPrice");
  468.                        subtotal9 = 0.0;
  469.                        subtotal9 = Iqty * price;
  470.                        out.println("RM" + subtotal9);
  471.                    %>
  472.                 </td>
  473.                 <td>
  474.                     <input type="hidden" name="order9" value="<%=order9%>">
  475.                     <input type="submit" value="Update Order">
  476.                     </form>
  477.  
  478.                 </td>
  479.             </tr>
  480.             <%
  481.                }
  482.                //end one product
  483.                //start one product
  484.                if ((order10.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order10")) != null) && (((String) session.getAttribute("qty10")) != null)) {
  485.            %>
  486.  
  487.             <tr>
  488.                 <td>
  489.                     <%=resultSet.getString("productName")%>
  490.                 </td>
  491.                 <td>
  492.                     <form name="orderCart" action="updateCart.jsp" method="POST">
  493.                         <input type='text' name='qty10' id='qty10' value="<%=qty10%>" size="1" />
  494.                         <input type='button' name='add' onclick='javascript: document.getElementById("qty10").value++;' value='+'/>
  495.                         <input type='button' name='subtract' onclick='javascript: document.getElementById("qty10").value--;' value='-'/>
  496.                 </td>    
  497.                 <td>
  498.                     <%
  499.                        int Iqty = Integer.parseInt(qty10);
  500.                        double price = resultSet.getDouble("productPrice");
  501.                        subtotal10 = 0.0;
  502.                        subtotal10 = Iqty * price;
  503.                        out.println("RM" + subtotal10);
  504.                    %>
  505.                 </td>
  506.                 <td>
  507.                     <input type="hidden" name="order10" value="<%=order10%>">
  508.                     <input type="submit" value="Update Order">
  509.                     </form>
  510.  
  511.                 </td>
  512.             </tr>
  513.             <%
  514.                        }
  515.                        //end one product
  516.  
  517.                    }
  518.  
  519.                    connection.close();
  520.                } catch (Exception e) {
  521.                    out.println(e);
  522.                }
  523.  
  524.            %>
  525.             <tr>
  526.                 <td colspan="2" border="0">
  527.                     <%out.println("<center>TOTAL :</center>");%>
  528.                 </td>
  529.                 <td colspan="2" border="0">
  530.                     <%
  531.                        if ((((String) session.getAttribute("qty1")) != null) && (((String) session.getAttribute("qty2")) != null)) {
  532.                            int Iqty = Integer.parseInt(qty1);
  533.                            int Iqty2 = Integer.parseInt(qty2);
  534.                        }
  535.                        double total = 0.0;
  536.                        total = subtotal1 + subtotal2 + subtotal3 + subtotal4 + subtotal5 + subtotal6 + subtotal7 + subtotal8 + subtotal9 + subtotal10;
  537.                        out.println("<center>RM" + total + "</center>");
  538.  
  539.                     %>
  540.                 </td>
  541.             </tr>
  542.         </table>
  543.     </form>
  544.     <p></p>
  545.     <form action="payment.jsp">
  546.         <input type="submit" value="Confirm Order" />
  547.     </form>
  548. </body>
  549. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement