jsp出现错误:Cannot invoke "java.util.List.iterator()" because "products" is null

<%@ page import="pojo.Product" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 12443
  Date: 2022/5/12
  Time: 15:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    List<Product> products = (List<Product>) request.getSession().getAttribute("productList");
%>

<table>
    <tr>
        <th>产品ID</th>
        <th>产品名称</th>
        <th>产品数量</th>
        <th>产品单价</th>
        <th></th>
    </tr>
    <%
        for (Product product: products){
    %>
    <tr>
        <td><%=product.getId()%></td>
        <td><%=product.getName()%></td>
        <td><%=product.getCount()%></td>
        <td><%=product.getPrice()%></td>
        <td><a href="/web/productServlet?id=<%=product.getId()%>&fun=productPurchase">购买</a></td>
    </tr>
    <%
        }
    %>
</table>
</body>
</html>

报错

img

img

products 后端传过来的值是null,检查下后台代码。

如有帮助,谢谢采纳~