码迷,mamicode.com
首页 > Web开发 > 详细

HttpServletRequest获取请求参数

时间:2019-01-02 15:14:46      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:ati   exce   stp   ram   smo   final   ring   value   接收   

 

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

HttpServletRequest获取请求参数

标签:ati   exce   stp   ram   smo   final   ring   value   接收   

原文地址:https://www.cnblogs.com/jakin3130/p/10208130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!