日期:2014-05-18  浏览次数:20817 次

checkbox与vector传送问题
通过checked判断数值加入到vector中传递,为什么t2.jsp收到为空值??请帮忙看看有什么问题,谢谢!

t1.jsp
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.*,java.util.* "   errorPage= " "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 测试数组传送 </title>
</head>

<body>
<form   id= "form1 "   name= "form1 "   method= "post "   action= "t2.jsp ">
    <input   name= "test1 "   type= "checkbox "   value= "value1 "   checked= "checked "   /> 测试1 <br   />
    <input   type= "checkbox "   name= "test2 "   value= "value2 "   /> 测试2 <br   />
    <input   type= "checkbox "   name= "test3 "   value= "value3 "   /> 测试3 <br   />
    <input   type= "checkbox "   name= "test4 "   value= "value4 "   /> 测试4 <br   />
    <input   type= "submit "   name= "Submit "   value= "提交 ">
</form>
</body>
</html>
<%   Vector   test   =   new   Vector();
  //   Vector   buyList=(Vector)session.getValues( " ", " ");
    //document.form1.test.checked   ;
%>
<script>
    if   (   document.form1.test1.checked   ==   true   )
    {   <%   test.add( "value1 ");   %> ;}else
    { <%   test.remove( "value1 ");   %> ;};
    if   (   document.form1.test2.checked   ==   true   )
    {   <%   test.add( "value2 ");   %> ;}else
    { <%   test.remove( "value2 ");   %> ;};
    if   (   document.form1.test3.checked   ==   true   )
    {   <%   test.add( "value3 ");   %> ;}else
    { <%   test.remove( "value3 ");   %> ;};
    if   (   document.form1.test4.checked   ==   true   )
    {   <%   test.add( "value4 ");   %> ;}else
    { <%   test.remove( "value4 ");   %> ;};    
</script>
<%
session.setAttribute( "test ",test);
%>


t2.jsp
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.*,java.util.* "   errorPage= " "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transi