Java JSTL foreach隐藏输入提交空值

Java JSTL foreach隐藏输入提交空值,java,forms,servlets,foreach,el,Java,Forms,Servlets,Foreach,El,我正在做一个类似于在线商店的小型JEE5应用程序,我需要展示商店产品,代码中可以更清楚地看到: <c:forEach var="product" items="${productsBean.products}"> <div class ="product"> <table> <td> <c:out value="${product.id}"/> </td> <td>

我正在做一个类似于在线商店的小型JEE5应用程序,我需要展示商店产品,代码中可以更清楚地看到:

<c:forEach var="product" items="${productsBean.products}">
  <div class ="product">
   <table>
    <td>
     <c:out value="${product.id}"/>
    </td>
    <td>
     <c:out value="${product.name}"/>
    </td>
    <td>
     <c:out value="${product.price}"/>
    </td>
    <td>
     <c:out value="${product.description}"/> 
    </td>
    <td>
    <form method="post" action="/servlets-war/AddToCart">
     <input type="hidden" name="id" value="${product.id}"></input>
     <input type="submit" value="add to cart"/>    
    </form>
   </td>
  </table>
 </div>
</c:forEach>

您正在将
id
作为请求属性进行检索

int id = Integer.parseInt((String)request.getAttribute("id"));
表单输入作为请求参数发送到servlet。适当更改代码:

int id = Integer.parseInt((String)request.getParameter("id"));

在HTML表单中正确设置了该值(检查页面源代码)?谢谢,您是对的,现在应用程序工作正常。
int id = Integer.parseInt((String)request.getParameter("id"));