源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

java遍历http请求request的所有参数实现方法

  • 时间:2022-09-22 02:17 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:java遍历http请求request的所有参数实现方法
通过程序遍历http请求的所有参数放到hashmap中,用的时候方便了。 如果参数值有中文,那么需要在程序中添加filter转码,或者在下面程序里,对paramValue转码 [b]如下所示:[/b]
public void doGet(HttpServletRequest request, HttpServletResponse response) 
   throws ServletException, IOException { 
Map map = new HashMap(); 
   Enumeration paramNames = request.getParameterNames(); 
  while (paramNames.hasMoreElements()) { 
   String paramName = (String) paramNames.nextElement(); 
 
   String[] paramValues = request.getParameterValues(paramName); 
   if (paramValues.length == 1) { 
    String paramValue = paramValues[0]; 
    if (paramValue.length() != 0) { 
     System.out.println("参数:" + paramName + "=" + paramValue); 
     map.put(paramName, paramValue); 
    } 
   } 
  } 
}
以上就是小编为大家带来的java遍历http请求request的所有参数实现方法的全部内容了,希望对大家有所帮助,多多支持编程素材网~
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部