【发布时间】:2017-02-21 05:51:30
【问题描述】:
我正在创建一个小型购物车项目,我在其中从 servlet 获取链接列表中的产品列表。现在,我将链表的值打印在一个表格中,用户可以选择他们想要的数量。 选择了哪个数量的应该作为属性进入下一页
以下是我面临的几个问题:
1:由于列表有超过 1 个项目,因此列出的每个项目都应该有 输入字段。如何动态更改输入名称 以后可以用作属性的数量。
2:商品的可用数量因产品而异,如何 我将数量的最大值设置为可用库存。
3:如果我可以设法获取值,我如何设置所有属性。 是在for循环里面还是for循环外面?
这是参考代码。Picture of what the page looks like
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%-- <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> --%>
<%@page import="shoppingcart.model.items.*,java.util.*" %>
<%List<ItemDetailsPojo> listp = (List<ItemDetailsPojo>) session.getAttribute("ItemsData");
%>
<%-- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> --%>
<Center>
<h3 style="color: blue">Welcome To the World of Shopping</h3>
</Center>
<div align='right'>Logged in as:</div>
<div align="center">
<table border="10" cellpadding="5">
<caption>
<h2>List of Items</h2>
</caption>
<tr>
<th>ItemId</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Available</th>
<th>Quantity</th>
</tr>
<%for(int i=0;i<listp.size();i++){%>
<tr>
<td><%out.println(listp.get(i).getItemId());%></td>
<td><%out.println(listp.get(i).getItemName());%></td>
<td><%out.println(listp.get(i).getCategory());%></td>
<td><%out.println(listp.get(i).getPrice());%></td>
<td><%out.println(listp.get(i).getQuantity());%></td>
<% int number = listp.get(i).getQuantity(); %>
<td><input type="number" name="should dynamically change according to the size of the list" min="0" max="should change according the the quantity available"></td>
</tr>
<%} %>
</table>
</div>
</body>
</html>
【问题讨论】: