[i] public static String getStringParameter(HttpServletRequest request,
String name, String defaultValue) {
String value = request.getParameter(name);
if (value != null && "get".equalsIgnoreCase(request.getMethod())) {
try {
value = URLDecoder.decode(
new String(value.getBytes("ISO-8859-1"), request
.getCharacterEncoding()), request
.getCharacterEncoding());
} catch (Throwable t) {
}
}
if (value == null) {
value = defaultValue;
}
return value;
}[/i]
String name, String defaultValue) {
String value = request.getParameter(name);
if (value != null && "get".equalsIgnoreCase(request.getMethod())) {
try {
value = URLDecoder.decode(
new String(value.getBytes("ISO-8859-1"), request
.getCharacterEncoding()), request
.getCharacterEncoding());
} catch (Throwable t) {
}
}
if (value == null) {
value = defaultValue;
}
return value;
}[/i]
本文介绍了一个用于处理HTTP请求中特定参数的Java方法。该方法能够从HttpServletRequest对象中获取指定名称的参数,并支持默认值设置。此外,对于GET请求,该方法还包括了对参数进行编码解码的处理,确保字符集的正确解析。
1421

被折叠的 条评论
为什么被折叠?



