0

I have this problem where I am trying to get items from an ArrayList from a servlet and display it to a JSP file but when I try to get the variables from the item in the ArrayList, they don't show up.

Here is my JSP file

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.product.Product"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport"
    content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<script src="https://kit.fontawesome.com/256fd9e75f.js"
    crossorigin="anonymous"></script>
<link rel="stylesheet"
    href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css"
    integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
    crossorigin="anonymous" />
<link rel="stylesheet" href="styles.css" />
<title>Home</title>
<link rel="icon" href="src/ShopLogo.png" type="image/x-icon" />
</head>
<body>
    <nav class="navbar fixed-top navbar-expand-md navbar-light"
        style="background-color: #f15c55"> <span
        class="navbar-brand mb-0 h1">Store</span>
    <button type="button" data-toggle="collapse" data-target="#navbarNav"
        class="navbar-toggler" aria-controls="navbarNav" aria-expanded="false"
        aria-label="Toggle Nav">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav">
            <li class="nav-item active"><a href="ProductLoaderServlet"
                class="nav-link">Home</a></li>
            <li class="nav-item active"><a href="product.html"
                class="nav-link">Top Products</a></li>
            <li class="nav-item active"><a href="cart.html" class="nav-link"><i
                    class="fa-regular fa-cart-shopping"></i></a></li>
        </ul>
    </div>
    </nav>
    <div class="image-overlay">
        <img src="scr/main/resources/Shop.jpg" alt="" />
        <h1 class="centered">Shop</h1>
    </div>
    <%
    ArrayList<Product> products = (ArrayList) request.getAttribute("products");
    for (Product product : products) {
    %>
    <div class="cards">
        <div class="card" style="width: 18rem">
            <img class="card-img-top" src="<%product.getImgUrl();%>" alt="Image" />
            <div class="card-body">
                <h5 class="card-title">
                    <%
                    product.getName();
                    %>
                </h5>
                <a href="#" class="btn btn-primary">Details</a>
            </div>
        </div>
    </div>
    <%
    }
    %>

</body>
</html>

and this is what I see My View

I assume that I am able to get the items because I can see 5 cards

But I want to know why my variables such as (name, or the image) aren't showing up

Many Thanks for your help

James Pat
  • 1
  • 2

0 Answers0