jsp获取单选按钮组件的值

jsp获取单选按钮组件的值

1.首先,写一个带有单选按钮组件的前台页

 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 男:<input type="radio" name="gender" value="男" />
12 
13 女:<input type="radio" name="gender" value="女" />
14 <br>
15 <input type="submit" />
16 </form>
17 </body>
18 </html>

2.然后,在处理页获取单选按钮组件的值

 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>

猜你喜欢

转载自www.cnblogs.com/skyI/p/9570333.html