String[] req =  request.getParameterValues("test");
错了,应该是String req =  request.getParameterValues("test");
因为选择框只能选一个所以处理页面不能用数组取值,得用字符串取

解决方案 »

  1.   

    request.getParameterValues()的返回值市数组型的,那怎么循环输出全部结果?
      

  2.   

    你虽然设置为多选,提交的时候也确实是提交了你所选择的所有的选项,但是JAVA里用这种方式并不能得到.
    你应该把按钮类型设置为button,然后为他加上一个onclick事件,在这个事件里用JAVASCRIPT把你得到的数组处理成一个用逗号隔开的字符串,然后把这个字符串赋给一个隐藏变量.你取值的时候取这个隐藏变量的值即可.然后在JAVA里把取到的直分开.
    <%@ page contentType="text/html;charset=gb2312"%>
    <html>
    <head>
    <script>
    function func(){
      把你得到的数组处理成一个用逗号隔开的字符串a;
     .....
       aaa.test1.value = a;
       aaa.submi();
    }
    </script>
    </head>
    <body><form action = "11.jsp" method = "post" name = "aaa"><table><tr>
    <p><select size="2" name="test" multiple>
      <option>1111</option>
      <option>2222</option>
      <option>3333</option>
      <option>4444</option>
      <option>5555</option>
      <option>6666</option>
      <option>7777</option>
    </select></p>
    </tr>
    <input type = "hidden" name = "test1">
    </table>
    <input type = "button" value = "提交" onclick = "func()">
    </form>
    </body>
    </html>
    //////////////
    <%@ page contentType="text/html;charset=gb2312"%> 
    <html><head></head><body>
    <% 
    int n = 0;
    String req =  request.getParameter("test1");然后在JAVA里把取到的直分开</body></html>
      

  3.   

    for(int i = 0;i <= n ;i++){
     out.print(req[i]);
     }%>改成i < n
    i=n 时候,ArrayIndex 错误
      

  4.   

    <option>1111</option>--------------Option中的value没有,搞什么冬冬啊。大家的HTML水平还没我高?
      

  5.   

    for(int i = 0;i <= n ;i++){
     out.print(req[i]);
     }数组有越界问题 i<=n;改成i<n或者i<=(n-1)
      

  6.   

    function delit(){
    document.delfrm.v1.value="";
    if(document.delfrm.ChkUserDel.length){
    for(i=0;i<document.delfrm.ChkUserDel.length;i++){
    if(document.delfrm.ChkUserDel[i].checked){
    //document.delfrm.v1.value+=document.delfrm.ChkUserDel[i].value + ",";
    document.delfrm.v1.value+="'"+document.delfrm.ChkUserDel[i].value + "',";
    }//if
    }//for
    }//if
    else{
    if(document.delfrm.ChkUserDel.checked){
    //document.delfrm.v1.value+=document.delfrm.ChkUserDel.value + ",";
    document.delfrm.v1.value+="'"+document.delfrm.ChkUserDel[i].value + "',";
    }//if
    }//else
    return confirm("你确定要删除的用户为:" + document.delfrm.v1.value);
    }
    function selectidall()
    {
    for(i=0;i<document.delfrm.ChkUserDel.length;i++)
    {
    document.delfrm.ChkUserDel[i].checked = !document.delfrm.ChkUserDel[i].checked;
    }
    }
    //-->
    </SCRIPT>
    这段脚本是进行多选删除的 不过用的是复选框
    给楼主参考一下吧
      

  7.   

    你的select框没有value值
    你的jsp应该这样写:
    <%@ page contentType="text/html;charset=gb2312"%>
    <html>
    <head>
    </head>
    <body><form action = "11.jsp" method = "post"><table><tr>
    <p><select size="2" name="test" multiple>
      <option vlaue="1111">1</option>
      <option vlaue="2222">2</option>
      <option value="3333">3</option>
      <option value="4444">4</option>
      <option value="5555">5</option>
      <option value="6666">6</option>
      <option value="7777">7</option>
    </select></p>
    </tr></table>
    <input type = "submit" value = "提交">
    </form>
    </body>
    </html>
    ////////
    <%@ page contentType="text/html;charset=gb2312"%> 
    <html><head></head><body>
    <% 
    int n = 0;
    String[] req =  request.getParameterValues("test");
    n = req.length;
    for(int i = 0;i < n ;i++){
     out.print(req[i]);
     }%>
    </body></html>如果要选取全部的select框的值,按shift键选取,在11.jsp里,可以显示全部的值!!!
    我调试过!