我做了个小测试,获取radio的值
test.jsp如下:
<HTML>
<HEAD><TITLE>test</TITLE></TITLE>
<BODY>
<%!
String selection;
%>
<%
for (int i = 1; i <= 4; i++)
{
selection = "" + i;
%>
<FORM>
<INPUT type = "radio" name = selection value = "A"></INPUT> A<BR>
<INPUT type = "radio" name = selection value = "B"></INPUT> B<BR>
<INPUT type = "radio" name = selection value = "C"></INPUT> C<BR>
<INPUT type = "radio" name = selection value = "D"></INPUT> D<BR>
</FORM>
<%
}
%>
<FORM action = "testCon.jsp" method = "POST">
<INPUT type = "submit" value = "submit"></INPUT>
</FORM>
</BODY>
</HTML>
*********************************************
*********************************************
testCon.jsp如下:
<HTML>
<BODY>
<%
out.print(request.getParameter(""+1) + "<BR>");
out.print(request.getParameter(""+2) + "<BR>");
out.print(request.getParameter(""+3) + "<BR>");
out.print(request.getParameter(""+4) + "<BR>");
%>
</BODY>
</HTML>当我运行test.jsp然后选择按钮再提交,可是testCon.jsp页面上显示的是null,而不是我所选按钮的值,是参数没有传过去吗?请指教,谢谢。

解决方案 »

  1.   

     不好意思,test.jsp中<HEAD>行代码中改其中一个</TITLE>为</HEAD>。
      

  2.   

    你的这个FORM里面没有相应的radio,所以取值失败
    <FORM action = "testCon.jsp" method = "POST" > 
    a.html<html>
    <body>
    <form name="form1" action="a.html">
    <INPUT type = "radio" name = "selection" value = "A" > </INPUT > A <BR > 
    <INPUT type = "radio" name = "selection" value = "B" > </INPUT > B <BR > 
    <INPUT type = "radio" name = "selection" value = "C" > </INPUT > C <BR > 
    <INPUT type = "radio" name = "selection" value = "D" > </INPUT > D <BR > 
    <input type=button value=提交 onclick=onvalue()>
    </form>
    </body>
    </html>
    <script>
    function onvalue()
    {
    var vs = document.getElementsByName("selection");
    var val;
    for(var i=0;i<vs.length;i++){
    if(vs[i].checked){ 
    val=vs[i].value; 
    break; 

    }
    alert("value="+val);
    }
    </script>你测试一下这个HTML文件,相信对你有所帮助
      

  3.   

    out.print(request.getParameter("1") + " <BR >");