Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.1 kB
1
Indexable
Never
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Product List</title>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
        <style>
            .add-button {
                position: absolute;
                top: 10px;
                right: 10px;
            }
        </style>
    </head>
    <body>
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <div class="container">
                <a class="navbar-brand" href="#">Product List</a>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav ml-auto">
                        <li class="nav-item">
                            <span class="nav-link">Hello <%= session.getAttribute("fullname")%></span>
                        </li>
                        <li class="nav-item">
                            <button id="btnSignOut" onclick="signOut()" class="btn btn-link">Sign Out</button>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>

        <div class="container mt-4">


            <h1>Show Data</h1>
            <h2>Products</h2>
            <table id="productTable" class="table table-bordered">
                <thead>
                    <tr>
                        <th>Product ID</th>
                        <th>Product Name</th>
                        <th>Product Quantity</th>
                        <th>Product Price</th>
                        <th>Product Picture</th>
                        <th>Product Description</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <% List<Product> products = (List<Product>) request.getAttribute("products");
                        if (products != null && !products.isEmpty()) {
                            for (Product product : products) {
                    %>
                    <tr>
                        <td><%= product.getPro_id()%></td>
                        <td><%= product.getPro_name()%></td>
                        <td><%= product.getPro_quan()%></td>
                        <td><%= product.getPro_price()%></td>
                        <td>
                            <img src="<%= product.getPro_pic()%>" alt="Product Image" width="100" height="100">
                        </td>
                        <td><%= product.getPro_des()%></td>
                        <td>
                            <a href="updateP.jsp?productId=<%= product.getPro_id()%>" class="btn btn-primary btn-sm">Update</a>
                            <button onclick="deleteProduct('<%= product.getPro_id()%>')" class="btn btn-danger btn-sm">Delete</button>
                        </td>
                    </tr>
                    <% }
                    } else { %>
                    <tr>
                        <td colspan="7">No products found.</td>
                    </tr>
                    <% }%>
                </tbody>
            </table>



            <div class="text-right mb-3">
                <a href="addP.jsp" class="btn btn-primary">Add Product</a>
                <a href="addO.jsp" class="btn btn-primary">Add Order</a>
            </div>
        </div>

        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
        <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
        <script>
                                $(document).ready(function () {
                                    $('#productTable').DataTable();
                                    $('#orderTable').DataTable();
                                });

                                function deleteProduct(productId) {
                                    if (confirm("Are you sure you want to delete this product?")) {
                                        window.location.href = "deleteP.jsp?productId=" + productId;
                                    }
                                }

                                function deleteOrder(orderId) {
                                    if (confirm("Are you sure you want to delete this order?")) {
                                        window.location.href = "deleteO.jsp?orderId=" + orderId;
                                    }
                                }

                                function signOut() {
                                    document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
                                    document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
                                    window.location.href = "index.jsp?logout=true";
                                }
        </script>
    </body>
</html>