Untitled
unknown
plain_text
2 years ago
5.0 kB
4
Indexable
<%@page import="java.util.List"%>
<%@page import="Models.Product"%>
<%@page import="DAOs.ProductDAO"%>
<%@page import="Models.Account"%>
<%@page import="DAOs.AccountDAO"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<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: fixed;
bottom: 20px;
right: 20px;
}
</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">
<%-- Kiểm tra cookie đã được xóa thành công hay chưa --%>
<% if (request.getParameter("logout") != null) { %>
<div class="alert alert-success" role="alert">
Logout successful! Cookie has been removed.
</div>
<% } %>
<h1>Show Data</h1>
<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>
<%
ProductDAO dao = new ProductDAO();
List<Product> products = dao.getAllProducts();
if (!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><%= product.getPro_pic()%></td>
<td><%= product.getPro_des()%></td>
<td>
<!-- Nút "Update" -->
<a href="update.jsp?productId=<%= product.getPro_id()%>" class="btn btn-primary btn-sm">Update</a>
<!-- Nút "Delete" -->
<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>
<a href="add.jsp" class="btn btn-primary add-button">Add Product</a>
<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();
});
function deleteProduct(productId) {
if (confirm("Are you sure you want to delete this product?")) {
window.location.href = "delete.jsp?productId=" + productId;
}
}
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>
Editor is loading...