这里截获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
JSP中截获POST或GET请求提交的所有参数
最新推荐文章于 2020-10-10 15:08:29 发布