zoukankan      html  css  js  c++  java
  • request获取请求参数通用方式

    
    
    package com.hopetesting.web.request;

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.util.Enumeration;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;

    /**
    * @author newcityman
    * @date 2019/8/31 - 18:20
    */
    @WebServlet("/requestDemo06")
    public class RequestDemo06 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    System.out.println("========");
    System.out.println(username + ":::" + password);
    String[] hobbies = request.getParameterValues("hobby");
    for (String hobby : hobbies) {
    System.out.println(hobby);
    }
    System.out.println("===================================");
    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
    String s = parameterNames.nextElement();
    System.out.println(s);
    String parameter = request.getParameter(s);
    System.out.println(parameter);
    }
    System.out.println("++++++++++++++++++++++++++++++++++++");

    Map<String, String[]> parameterMap = request.getParameterMap();
    Set<String> strings = parameterMap.keySet();
    for (String name : strings) {
    String[] values = request.getParameterValues(name);
    System.out.println(name);
    for (String value : values) {
    System.out.println(value);
    }
    System.out.println("+++++++++++++++++++++++++++++++++++++++");
    }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request, response);
    }
    }
     
  • 相关阅读:
    亚马逊云IoT平台接入开发记录
    pip下载速度慢更换清华源试试
    gitlab回归上一次提交
    uos桌面壁纸存放路径
    python中json中的dump和dumps
    Python中的类中__dict__方法
    C++ | 数组反转的三种方法
    《C++Primer Plus》 | 复合类型
    pwn 中的函数 | 持续更新
    七月安恒DASCTF | 复现
  • 原文地址:https://www.cnblogs.com/newcityboy/p/11440090.html
Copyright © 2011-2022 走看看