出错代码如下:
    。
    。
    。
    <%
    while(rs.next()){
product_name = rs.getString("PRODUCT_NAME");
price = rs.getFloat("PRICE");
description = rs.getString("DESCRIPTION");
product_id = rs.getString("PRODUCT_ID");
 %>
 <form id = "form" method = "post" action = "delete_products.jsp">
  <tr>
    <td>&nbsp;产品名称:<%=product_name%></td><td width="40%">&nbsp;报价:<span style="color:#FF0000; font-style:italic;"><%=price%></span></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;描述:<%=description%></td>
<td><input type = "hidden" name = "product_id" value = "<%=product_id%>"><input  name = "delete" type = "button" value = "删除"  onclick = "goto('delete_products.jsp');">&nbsp;&nbsp;<input name = "change" type = "button" value = "修改" onclick = "goto('change_products.jsp');"><%=product_id%></td>  </tr>
  </form>
  <tr><td height="5" colspan="2"><hr size="3" width="50%"/></td></tr>
<%
   }
     。
     。
     。 问题是:我想要的功能是 每当点击 修改 或者删除的时候  product_id 这个隐藏值  被传递到其它页面 
但是 每次都是把我第一条记录 传过去  
如何 才能 变成 我点击 那条记录 就传递 对应的隐藏值过去呢?
如 product_id 对应的值 有  
1   修改 删除
2   修改 删除
3   修改 删除
4   修改 删除

当我点击   3 的修改或删除是 传递的值 是3  而不是 1 

解决方案 »

  1.   

    goto函数怎么写的   form不要放在while里面  这样有很多form id还重复  也可以直接用超链接  href='delete_products.jsp?id=<%=product_id%>'
      

  2.   

    goto('delete_products.jsp')改成goto('delete_products.jsp?id= <%=product_id%>')
    goto('change_products.jsp')改成goto('change_products.jsp?id= <%=product_id%>')
    删除隐藏值
    原因是由于product_id值有多个,你得到的总是第一个
      

  3.   

    附全代码上去了 
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!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=gb2312">
    <title>仓库管理首页</title>
    <link rel="stylesheet" href="register.css" type="text/css"/>
    </head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function goto(act){ 
          var a = document.getElementById('form');
      a.action = act;
      a.submit();
        } 
    //-->
    </SCRIPT><%
    String UserId = (String)session.getAttribute("user");
    if(UserId == null || UserId == "")
         response.sendRedirect("login.jsp");
    String product_id = "";
    String product_name = "";
    float price;
    String description = "";Connection con = null;
    Statement sm = null;
    ResultSet rs = null;
    try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=d:/DataBase/gys.mdb";   //注意修改路径
      con=DriverManager.getConnection(url) ; 
        sm = con.createStatement();
        rs = sm.executeQuery("select * from products1"); 
    }catch(Exception e){
        e.printStackTrace();
    }
    %>
    <body>
    <table width="80%" align="center">
      <tr>
        <td class="title">&nbsp;仓库货物管理==========&nbsp;&nbsp;<a href = "addproducts.jsp" class="title1">添加商品</a>&nbsp;&nbsp;==========</td>
        <td style="width:150; height:20; vertical-align:middle; text-align:center;"><%=UserId%>&nbsp;您好!&nbsp;&nbsp;<a href="login.jsp">登录</a>&nbsp;|&nbsp;<a href="adminlogout.jsp">注销</a></td>
      </tr>
    </table>
    <hr align="center" width="75%" color="#990000" size="1"/>
    <table width="80%" align="center">
      <tr><td height="5" colspan="2"></td></tr>
      <form id = "form" method = "post" action = "delete_products.jsp">
     <%
        while(rs.next()){
    product_name = rs.getString("PRODUCT_NAME");
    price = rs.getFloat("PRICE");
    description = rs.getString("DESCRIPTION");
    product_id = rs.getString("PRODUCT_ID");
     %>  <tr>
        <td>&nbsp;产品名称:<%=product_name%></td><td width="40%">&nbsp;报价:<span style="color:#FF0000; font-style:italic;"><%=price%></span></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;描述:<%=description%></td>
    <td><input type = "hidden" name = "product_id" value = "<%=product_id%>"><input  name = "delete" type = "button" value = "删除"  onclick = "goto('delete_products.jsp');">&nbsp;&nbsp;<input name = "change" type = "button" value = "修改" onclick = "goto('change_products.jsp');"><%=product_id%></td>  </tr>
      </form>
      <tr><td height="5" colspan="2"><hr size="3" width="50%"/></td></tr>
    <%
       }
       rs.close();
        sm.close();

        con.close();
    %>
    </table>
    <div align="center" class="tail">2006==本公司版权拥有</div>
    </body>
    </html>
      

  4.   

    document.getElementById('form')   你有多个id为form的表单 他肯定每次都是第一个  用超链接的形式  只使用一个form  将while写在form里面
      

  5.   


    用超链接的形式  只使用一个form  将while写在form里面可以再具体一点吗? 
     
    谢谢 
      

  6.   

    <td><input type = "hidden" name = "product_id" value = "<%=product_id%>"><input name = "delete" type = "button" value = "删除" onclick = "goto('delete_products.jsp');">&nbsp;&nbsp;<input name = "change" type = "button" value = "修改" onclick = "goto('change_products.jsp');"><%=product_id%></td>  </tr> 
    因为我红色这里测试获取 product_id 已经正确了的啊 
    但 隐藏的 product_id 怎么传递 过去 不正确呢?
    还是 goto 的问题?
      

  7.   

    name = "product_id"   name重复了
      

  8.   

    while(rs.next()){ 
    product_name = rs.getString("PRODUCT_NAME"); 
    price = rs.getFloat("PRICE"); 
    description = rs.getString("DESCRIPTION"); 
    product_id = rs.getString("PRODUCT_ID"); 你这段代码有问题, 你这个product_name 对象都定义在这个 while 里面。
    while(rs.next()){ 
    Product  product= new Product();
    product.name = rs.getString("PRODUCT_NAME"); 
    product.price = rs.getFloat("PRICE"); 
    product.description = rs.getString("DESCRIPTION"); 
    product.id = rs.getString("PRODUCT_ID"); 
    }
    这样你试试。
      

  9.   

    不行  运行 都出错了  
    我觉得 问题 不 出在  product_name 对象都定义在这个 while 里面
    而是 在 隐藏参数传递不正确这里 PRODUCT_ID
      

  10.   

    有2种处理方法

    goto('delete_products.jsp')改成goto('delete_products.jsp?product_id= <%=product_id%>') 
    goto('change_products.jsp')改成goto('change_products.jsp?product_id= <%=product_id%>')方法goto中form提交改为用location.href提交用form提交时你将所有的product_id值都传过去了,根据那么获取的就是第一个值。二
     goto('delete_products.jsp')改成goto('delete_products.jsp?num= 当前的行位置) 
     goto('change_products.jsp')改成goto('change_products.jsp?num= 当前的行位置)
    第一个出现product_id的num为0,依次类推
    然后跳转页面根据num的值获取对应的值
      

  11.   


    你先看是否传过去product_id 值;
    如若每次传进去的是固定的某个值的话 那就是 你的循环 没有正确结束,from的位置不对。
      

  12.   


    但是本页面我引用 product_id值 是正确显示了的啊  按道理说 循环显示 正确了的啊 
    但就是 传递的时候 传递第一条记录的 product_id 值  过去
    郁闷中 
      

  13.   

    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
    function goto(act){ var a = document.getElementById('form'); a.action = act; a.submit();    } 
    //--> 
    </SCRIPT> 问题在这里
    你可以在运行时,去看一下网页源码,已经产生了多个id=form 的表单了,
    而这个goto用的是getElementById('form')只能得到第一个form你现在的思路很混乱,需要找个好的例子去学习以下
      

  14.   


    那 请问下 如何 才能得到 我想传递 的 那一个 form呢?
    我的本意就是想传递一个form的啊