JAVA-JSP內置對象之request獲得參數的所有參數值(多個值)


 

相關資料:
《21天學通Java Web開發》

獲得參數的所有參數值(多個值)
1.需要使用request對象的getParameterValues()方法。

RequestForm4.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
 2 <html>
 3 <head>
 4   <title>表單</title>
 5 </head>
 6 <body>
 7   <form action="RequestDemo4.jsp" method="post">
 8     用戶名:<input type= "text" name="username"/><br>
 9     用戶密碼:<input type= "password" name="userpassword"/><br>
10  喜歡的運動: 11     <input type = "checkbox" name="sport" value="pingpang">乒乓球 12     <input type = "checkbox" name="sport" value="badketball">籃球 13     <input type = "checkbox" name="sport" value="football">足球<br>
14     <input type="submit" value="提交">
15   </form>
16 </body>
17 </html>
View Code

 

RequestDemo4.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" import="java.util.*" %>
 2 <html>
 3 <head>
 4   <title>使用request對象獲得參數的所有參數值</title>
 5 </head>
 6 <body>
 7   <%-- 通過request對象的getParameterValues獲得參數的所有參數值 --%>  
 8   <% 
 9     String[] strArr = request.getParameterValues("sport");//獲得所有的參數值 10  out.println("喜歡的運動:");//輸出信息 11     for(String str: strArr){ //遍歷字符串數組取出參數值 12  out.println(str); //輸出參數值 13  } 14   %>
15 </body>
16 </html>
View Code

 


免責聲明!

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



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