我正在创建一个购物门户。在这个门户中,我有一个购物车页面,其中显示了选择的项目,并带有一个用于输入所需数量的文本字段。我已经使用 while 循环对它们进行了编号cart.jsp
。我正在检索那些 vales bill.jsp
。我得到了第一个值,但其他值也与第一个值相同,而不是我们给出的值。有谁知道出了什么问题?
购物车.jsp
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
<title>Shopping cart</title>
<style type="text/css">
* { font-size: 12px; font-family: Verdana }
</style>
<base href="%3C%=basePath%%3E">
<title>My JSP 'bill.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<img src="images/add.png" onclick="document.location='index.jsp'" alt="** PLEASE DESCRIBE THIS IMAGE **"> <img src="images/remove.png" onclick="document.location='remove.jsp'" alt="** PLEASE DESCRIBE THIS IMAGE **"> <img src="images/cart.png" onclick="document.location='cart.jsp'" alt="** PLEASE DESCRIBE THIS IMAGE **">
<h2>The shopping cart</h2>
<![CDATA[
int i = 1;
java.util.Enumeration content = session.getAttributeNames();
out.println("<form name=f1 action=bill.jsp>");
out.println("<table>");
while (content.hasMoreElements()) {
out.println("<tr>");
out.println("<td>");
out.println(i);
out.println(content.nextElement());
out.println("</td>");
out.println("<td> <input type=text name=i>");
out.println("</td>");
i++;
}
out.println("</table>");
]]>
<a href="index.jsp"></a>
<h3><a href="index.jsp"><strong>Continue Shopping</strong></a></h3>
<a href="remove.jsp"><strong>Remove items From Cart</strong></a>
<form><input type="submit" value="generate bill"></form>
比尔.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -->
<!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->
<![CDATA[
int i = 1;
java.util.Enumeration content = session.getAttributeNames();
out.println("<form name=f2>");
out.println("<table>");
while (content.hasMoreElements()) {
out.println("<tr>");
out.println("<td>");
out.println(i);
out.println(content.nextElement());
out.println("</td>");
out.println("<td>");
String a = request.getParameter("i");
out.println(a);
out.println("</td>");
i++;
}
out.println("</table>");
out.println("</form>");
]]>
<br>
</body>
</html>