Java/JSP/Form Radio Button
Версия от 18:01, 31 мая 2010; (обсуждение)
Submitting Radio Buttons
//File: index.html
<HTML>
<HEAD>
<TITLE>Submitting Radio Buttons</TITLE>
</HEAD>
<BODY>
<H1>Submitting Radio Buttons</H1>
<FORM ACTION="formAction.jsp" METHOD="post">
<INPUT TYPE="radio" NAME="radios" VALUE="radio1" CHECKED>
Radio Button 1
<BR>
<INPUT TYPE="radio" NAME="radios" VALUE="radio2">
Radio Button 2
<BR>
<INPUT TYPE="radio" NAME="radios" VALUE="radio3">
Radio Button 3
<BR>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</BODY>
</HTML>
//File: formAction.jsp
<HTML>
<HEAD>
<TITLE>Reading Radio Buttons</TITLE>
</HEAD>
<BODY>
<H1>Reading Radio Buttons</H1>
<%
if(request.getParameter("radios") != null) {
if(request.getParameter("radios").equals("radio1")) {
out.println("Radio button 1 was selected.<BR>");
}
else {
out.println("Radio button 1 was not selected.<BR>");
}
if(request.getParameter("radios").equals("radio2")) {
out.println("Radio button 2 was selected.<BR>");
}
else {
out.println("Radio button 2 was not selected.<BR>");
}
if(request.getParameter("radios").equals("radio3")) {
out.println("Radio button 3 was selected.<BR>");
}
else {
out.println("Radio button 3 was not selected.<BR>");
}
}
%>
</BODY>
</HTML>