addUser.jsp
......................
<form action="chaddUser.jsp?rankId=<%=rankId%>" method="post" name="form1" enctype="multipart/form-data">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<%
  int index = -1;
%> 
 <tr>
  <td></td>
  <td>选择角色:</td> 
  <td>项目名称</td>
  <td>角 色</td>
 </tr>
<tr>
  <td height="8" colspan="6"></td>
 </tr>
<%
  sql="SELECT pName,pID FROM project";
  rs=stmt.executeQuery(sql);
  while(rs.next())
  {
  int pID=rs.getInt("pID");
  String pName=rs.getString("pName");
%> 
 <tr>
  <td></td>
  <td></td>
  <td width="156"><%=pName%></td>
  <td width="409">
<%
  index++; 
%>
   <input type="hidden" name="pID[<%=index%>]" value="<%=pID%>">
   <select name="projectRole[<%=index%>]">
    <option value="4" selected>None</option>
    <option value="1">管理员</option>
    <option value="2">编辑者</option>
    <option value="3">浏览者</option>
   </select>
  </td>
 </tr> 
<%
  }
%>
.............................
chaddUser.jsp
..........
ArrayList pIDs = (ArrayList)session.getAttribute("pID");
ArrayList projectRoles = (ArrayList)session.getAttribute("projectRole");
if(pIDs!=null&&projectRoles!=null)
{
  for (int counter = 0; counter < pIDs.size()&&counter < projectRoles.size (); counter++ ) 
{
   pID = (String)pIDs.get(counter); 
   projectRole = (String)projectRoles.get(counter); 
   sql1="INSERT INTO person_role(person_id,project_id,role_id) VALUES('"+uId+"','"+pID+"','"+projectRole+"')";
   stmt1.executeQuery(sql1);
   valid=true; 
 }
}
................
问题:我想把addUser.jsp中的项目ID(pID[<%=index%>])和项目角色
(projectRole[%=index%])传给chaddUser.jsp。但是现在不知道如何获取它们的值。其中的chaddUser.jsp中的ArrayList是我自己写的
请各位高人多多指点如何写这个代码。。

解决方案 »

  1.   

    页面中
    <input type="hidden" name="pID" value="<%=pID%>">name必须是相同的然后
    String[] pIDs = request.getParameterValues("pID");
      

  2.   

    但是我用<%=pIDs%>验证得到的是null(空值).
    再问一下怎样把这个数组值插入到数据库中,
    用这个可以吗:
    sql1="INSERT INTO person_role(person_id,project_id,role_id) VALUES('"+uId+"','"+pIDs+"','"+projectRoles+"')";
    请各位多多指点..............
      

  3.   

    String[] pIDs = request.getParameterValues("pID");
    这个方法只对checkbox有用,在这个数组中是没有用的,请各位高手能不能指点一下啊,
    我已经调试了2天了...........................
      

  4.   

    <%
       //先求出总数,这个你应该能求出来之后
       int zong=10;
       String shuzu[]=new String[zong];
       for(int i=0;i<zong;i++)
       {
          shuzu[i]=request.getParameter("pID"+shuzu[i]);
      
       String sql1="INSERT INTO person_role(project_id) VALUES("+shuzu[i]+")";
       stmt1.executeQuery(sql1);   
       }
       //应该就是这个意思,你琢磨琢磨!
    %>
      

  5.   

    怎样获取addUser.jsp中的项目ID(pID[<%=index%>])和项目角色(projectRole[%=index%])
    的值呢