您的位置:首页 > Web前端 > JavaScript

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

2009-06-12 13:04 507 查看
这里截获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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: