zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    JavaScript的continue、break和return的区别
    JavaScript的函数和作用域闭包
    利用反射快速给Model实体赋值
    C# 多态的实现
    C# 去除字符串首尾字符或字符串
    C#中大List的内存分配
    C#实现对图片文件的压缩、裁剪操作实例
    StringBuilder String string.Concat 字符串拼接速度
    C# 事件浅析
    理解 Thread.Sleep 函数
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/7669978.html
Copyright © 2011-2022 走看看