zoukankan      html  css  js  c++  java
  • JAVA-JSP内置对象之request获得封装所有参数值的Map

    相关资料:
    《21天学通Java Web开发》

    获得封装所有参数值的Map
    1.通过request对象的getParameterMap()方法来获得封装所有的参数值的Map对象。
    2.通过该Map对象可以获得指定参数的参数值。

    RequestForm5.jsp

     1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>表单</title>
     5 </head>
     6 <body>
     7   <form action="RequestDemo5.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

    RequestDemo5.jsp

     1 <%@ page language="java" contentType="text/html;charset=gb2312" import="java.util.*" %>
     2 <html>
     3 <head>
     4   <title>使用request对象获得封装所有参数值的Map</title>
     5 </head>
     6 <body>
     7   <%-- 通过request对象的getParameterMap封装所有的参数值的Map --%>  
     8   <% 
     9     Map<String, String[]> mapParamter = request.getParameterMap();//获得封装备的有参数值的Map
    10     String[] strUsername = (String[])mapParamter.get("username");//获得其中的username参数值
    11     out.println("用户名:"+strUsername[0]+"<br>");//打印输出username参数值
    12     String[] strPassword = (String[])mapParamter.get("userpassword");//获得suerpassword参数值
    13     out.println("用户密码:"+strPassword[0]+"<br>");//打印输出userpassword参数值
    14     String[] strSport = (String[])mapParamter.get("sport");//获得其中的sport参数值
    15     out.println("喜欢的运动:");
    16     for(String sport:strSport){
    17       out.println(sport);//遍历打印输出sport参数值
    18     }    
    19   %>
    20 </body>
    21 </html>
    View Code
  • 相关阅读:
    CSS 实现隐藏滚动条同时又可以滚动
    在vue项目中的axios使用配置记录
    QS:vue中qs的使用
    Electron 无边框窗口最大化最小化关闭功能
    CSS样式表能否控制文字禁止选择,复制, 焦点
    yarn 在Vue框架中的常用命令
    Vue 实现左边导航栏且右边显示具体内容(element-ui)
    Vuex 存储||获取后台接口数据
    软件工程第二周开课介绍
    返回一个整数数组中最大子数组的和 (非环状 和环状)
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/7670031.html
Copyright © 2011-2022 走看看