我做了个小测试,获取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,而不是我所选按钮的值,是参数没有传过去吗?请指教,谢谢。
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,而不是我所选按钮的值,是参数没有传过去吗?请指教,谢谢。
解决方案 »
- 求助:Calender日期是怎么回事?很诡异,附代码
- 求:用java给tif图片添加文字水印
- 请教高手关于重写方法的规则问题~~想不通。。。
- 关于finalize()使用
- 如何实现字符串反转?
- 如何进行地址传递
- 大家开发界面使用什么,有多少人使用Swing,觉得优势是什么?
- jdbc-odbc bridge 的问题
- 菜鸟求助:用什么办法替换 public boolean action(Event e,Object o) 和 public boolean handleEvent(Event e)?
- 有关encoding的一个问题
- 急!java调用构造函数问题.(20分.)
- 给学Java的大学生们分享一点经验(五)
<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文件,相信对你有所帮助