当前位置:   article > 正文

HttpServletRequest获取请求参数

serverhttprequest request 获取queryparam

 

通过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;
}

转载于:https://www.cnblogs.com/jakin3130/p/10208130.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/309925?site
推荐阅读
相关标签
  

闽ICP备14008679号