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

这里截获POST或GET请求提交的所有请求参数,并组成查询串返回
/***/ /**
*
*该方法用于将request中参数取出组成查询串后返回
*
*
@paramrequest
*HttpServletRequest
*
@returnString返回key1=value1&key2=value形式的查询串
*/

public static StringgetQueryString(HttpServletRequestrequest) ... {
try...{
booleanfirst=true;
StringBufferstrbuf
=newStringBuffer("");
EnumerationemParams
=request.getParameterNames();

do...{
if(!emParams.hasMoreElements())...{
break;
}

StringsParam
=(String)emParams.nextElement();
String[]sValues
=request.getParameterValues(sParam);
StringsValue
="";
for(inti=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));
}

elseif(sValue!=null&&sValue.trim().length()!=0
&&first==false)...{
strbuf.append(
"&").append(sParam).append("=").append(
URLEncoder.encode(sValue,
"GBK"));
}

}

}

while(true);

returnstrbuf.toString();
}
catch(UnsupportedEncodingExceptione)...{
throwRuntimeException(e);
}

}

你可能感兴趣的:(post)