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="request2.jsp" method="post">
11   喜歡的顏色:<br/>
12   紅:<input type="checkbox" name="color"  value="紅"/>
13   綠:<input type="checkbox" name="color"  value="綠"/>
14   藍:<input type="checkbox" name="color"  value="藍"/>
15 <hr/>
16 <input type="submit" />
17 </form>
18 </body>
19 </html>

2.寫一個處理頁獲取多選框組件的值

 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 <%
11  request.setCharacterEncoding("utf-8");
12  String[] color = request.getParameterValues("color");
13  %>
14  您喜歡的顏色
15  <%
16   for(String c : color){
17       out.println(c + " "); 
18   }
19  %> 
20 </body>
21 </html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM