这里截获POST或GET请求提交的所有请求参数,并组成查询串返回
/**
*
*该方法用于将request中参数取出组成查询串后返回
*
* @param request
*HttpServletRequest
* @return String返回key1=value1&key2=value形式的查询串
*/
public static StringgetQueryString(HttpServletRequestrequest) {
try {
boolean first = true ;
StringBufferstrbuf = new StringBuffer( "" );
EnumerationemParams = request.getParameterNames();
do {
if ( ! emParams.hasMoreElements()) {
break ;
}
StringsParam = (String)emParams.nextElement();
String[]sValues = request.getParameterValues(sParam);
StringsValue = "" ;
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 (UnsupportedEncodingExceptione) {
throw RuntimeException(e);
}
}
*
*该方法用于将request中参数取出组成查询串后返回
*
* @param request
*HttpServletRequest
* @return String返回key1=value1&key2=value形式的查询串
*/
public static StringgetQueryString(HttpServletRequestrequest) {
try {
boolean first = true ;
StringBufferstrbuf = new StringBuffer( "" );
EnumerationemParams = request.getParameterNames();
do {
if ( ! emParams.hasMoreElements()) {
break ;
}
StringsParam = (String)emParams.nextElement();
String[]sValues = request.getParameterValues(sParam);
StringsValue = "" ;
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 (UnsupportedEncodingExceptione) {
throw RuntimeException(e);
}
}