zoukankan      html  css  js  c++  java
  • HttpServletRequest获取请求参数

    通过HttpServletRequest接收请求来的参数,

    get请求

    public class controller1 {
    @RequestMapping(value = "/", method = {RequestMethod.POST})
    public String con001(HttpServletRequest request) throws IOException {
    Map<String, String> param = getAllRequestParam(request);
    String queryString = request.getQueryString();
    String user = request.getParameter("user");
    String pass = request.getParameter("pass");
    System.out.println(user);
    System.out.println(param);
    return "hello";
    }

    post请求

    先获取到参数名的集合,在组装到Map里

    private Map<String, String> getAllRequestParam(final HttpServletRequest request) {
    Map<String, String> res = new HashMap<String, String>();
    Enumeration<?> temp = request.getParameterNames();
    if (null != temp) {
    while (temp.hasMoreElements()) {
    String en = (String) temp.nextElement();
    String value = request.getParameter(en);
    res.put(en, value);
    }
    }
    return res;
    }
  • 相关阅读:
    1649. 超级棒棒糖
    1872. 连接棒材的最低费用
    二叉树的层级遍历转换
    ZMQ的三种消息模式
    logging日志
    Svn基本使用
    Pycharm快捷键
    Redis安装和连接
    整形转中文
    C# Socket连接 无法访问已释放的对象
  • 原文地址:https://www.cnblogs.com/jakin3130/p/10208130.html
Copyright © 2011-2022 走看看