title: Getting text box value with JSP
body: <p>I am creating a shopping portal.  In this portal, I have a cart page that displays the item chosen with a text field for entering the quantity needed.  I have numbered them using a while loop in <code>cart.jsp</code>.  I am retrieving those vales in <code>bill.jsp</code>. I am getting the first value but the other values are also the same as the first, not what we have given.  Does anyone know what is going wrong?</p>
  
  <p>cart.jsp</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org"&gt;
  &lt;title&gt;Shopping cart&lt;/title&gt;
  
  &lt;style type="text/css"&gt;
                         * { font-size: 12px; font-family: Verdana }
  &lt;/style&gt;
  &lt;base href="%3C%=basePath%%3E"&gt;
  &lt;title&gt;My JSP 'bill.jsp' starting page&lt;/title&gt;
  &lt;meta http-equiv="pragma" content="no-cache"&gt;
  &lt;meta http-equiv="cache-control" content="no-cache"&gt;
  &lt;meta http-equiv="expires" content="0"&gt;
  &lt;meta http-equiv="keywords" content="keyword1,keyword2,keyword3"&gt;
  &lt;meta http-equiv="description" content="This is my page"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;img src="images/add.png" onclick="document.location='index.jsp'" alt="** PLEASE DESCRIBE THIS IMAGE **"&gt; &lt;img src="images/remove.png" onclick="document.location='remove.jsp'" alt="** PLEASE DESCRIBE THIS IMAGE **"&gt; &lt;img src="images/cart.png" onclick="document.location='cart.jsp'" alt="** PLEASE DESCRIBE THIS IMAGE **"&gt;
  &lt;h2&gt;The shopping cart&lt;/h2&gt;
  &lt;![CDATA[
      int i = 1;
      java.util.Enumeration content = session.getAttributeNames();
      out.println("&lt;form name=f1 action=bill.jsp&gt;");
      out.println("&lt;table&gt;");
      while (content.hasMoreElements()) {
          out.println("&lt;tr&gt;");
          out.println("&lt;td&gt;");
          out.println(i);
          out.println(content.nextElement());
          out.println("&lt;/td&gt;");
          out.println("&lt;td&gt; &lt;input type=text name=i&gt;");
          out.println("&lt;/td&gt;");
          i++;
      }
      out.println("&lt;/table&gt;");
  ]]&gt;
  &lt;a href="index.jsp"&gt;&lt;/a&gt;
  &lt;h3&gt;&lt;a href="index.jsp"&gt;&lt;strong&gt;Continue Shopping&lt;/strong&gt;&lt;/a&gt;&lt;/h3&gt;
  &lt;a href="remove.jsp"&gt;&lt;strong&gt;Remove items From Cart&lt;/strong&gt;&lt;/a&gt;
  &lt;form&gt;&lt;input type="submit" value="generate bill"&gt;&lt;/form&gt;
  </code></pre>
  
  <p>bill.jsp</p>
  
  <pre><code>&lt;%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%&gt;
  &lt;%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  %&gt;
  &lt;!-- &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; --&gt;
  &lt;!-- &lt;link rel="stylesheet" type="text/css" href="styles.css"&gt; --&gt;
  &lt;![CDATA[ 
      int i = 1;
      java.util.Enumeration content = session.getAttributeNames();
      out.println("&lt;form name=f2&gt;");
      out.println("&lt;table&gt;");
      while (content.hasMoreElements()) {
          out.println("&lt;tr&gt;");
          out.println("&lt;td&gt;");
          out.println(i);
          out.println(content.nextElement());
          out.println("&lt;/td&gt;");
          out.println("&lt;td&gt;");
          String a = request.getParameter("i");
          out.println(a);
          out.println("&lt;/td&gt;");
          i++;
      }
      out.println("&lt;/table&gt;");
      out.println("&lt;/form&gt;");
  ]]&gt;
  &lt;br&gt;
  &lt;/body&gt;
  &lt;/html&gt;       
  </code></pre>