JSP gets the value of the radio button component.

jspGets the value of the radio button component.

1.First, write a foreground page with a radio button component.

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <form action="request1.jsp" method="post">
11 Male: < input type= "radio" name= "gender" value= "male" />12 
13 Female: < input type= "radio" name= "gender" value= "female" />14 <br>
15 <input type="submit" />
16 </form>
17 </body>
18 </html>

2.Then, get the value of the radio button component on the processing page.

 1 <%@page import="java.util.Enumeration"%>
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>Insert title here</title>
 9 </head>
10 <body>
11 <%
12 
13 request.setCharacterEncoding("utf-8");
14 
15 String gender = request.getParameter("gender");
16 
17 out.println(gender);
18 
19 %>
20 </body>
21 </html>

 

Leave a Reply

Your email address will not be published. Required fields are marked *