采用枚举获取前端传过来的请求参数

当传递的参数个数不固定且参数名没有重复的,取值的方法:

//得到枚举类型的参数名称,参数名称若有重复的只能得到第一个

  1. Map map = new HashMap();

  2. Enumeration enum =this.getRequest().getParameterNames();  
  3.  while (enum.hasMoreElements()) {  
  4.   String paramName = (String) enum.nextElement();  
  5.    
  6.   String paramValue = this.getRequest().getParameter(paramName);  
  7.    //形成键值对应的map  
  8.   map.put(paramName, paramValue);  
  9.   }  

猜你喜欢

转载自blog.csdn.net/qq_35509543/article/details/79991852