JSP中截获POST或GET请求提交的所有参数

这里截获POST或GET请求提交的所有请求参数,并组成查询串返回
 /** *//**
   *
   * 该方法用于将request中参数取出组成查询串后返回
   *
   * @param request
   *            HttpServletRequest
   * @return String 返回key1=value1&key2=value形式的查询串
   */
  public static String getQueryString(HttpServletRequest request)...{
 try...{
    boolean first = true;
    StringBuffer strbuf = new StringBuffer("");
    Enumeration emParams = request.getParameterNames();

    do ...{
      if (!emParams.hasMoreElements()) ...{
        break;
      }
      String sParam = (String) emParams.nextElement();
      String[] sValues = request.getParameterValues(sParam);
      String sValue = "";
      for (int i = 0; i < sValues.length; i++) ...{
        sValue = sValues[i];
        if (sValue != null && sValue.trim().length() != 0
            && first == true) ...{
          first = false;
          strbuf.append(sParam).append("=").append(
              URLEncoder.encode(sValue, GBK_ENCODE));
        }
        else if (sValue != null && sValue.trim().length() != 0
                 && first == false) ...{
          strbuf.append("&").append(sParam).append("=").append(
              URLEncoder.encode(sValue, "GBK"));
        }
      }
    }
    while (true);

    return strbuf.toString();
}catch(UnsupportedEncodingException e)...{
   throw RuntimeException(e);
}
  }

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/alan3258/archive/2008/05/28/2489106.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值