/** * Returns a request parameter.<br> * In addition the method fixes problems with incorrect UTF-8 characters returned by the servlet engine. * All character data is converted from ISO-8859-1 to UTF-8. * @param requestMap Request Parameter map. * @param param Parameter name. * @return Parameter value or null if it is not set. */ public static @Nullable String get(@NotNull Map<String, String[]> requestMap, @NotNull String param) { String value = null; String[] valueArray = requestMap.get(param); if (valueArray != null && valueArray.length > 0) { value = valueArray[0]; } // convert encoding to UTF-8 if not form encoding parameter is set if (value != null && !hasFormEncodingParam(requestMap)) { value = convertISO88591toUTF8(value); } return value; }
/** * Returns a request parameter.<br> * In addition the method fixes problems with incorrect UTF-8 characters returned by the servlet engine. * All character data is converted from ISO-8859-1 to UTF-8 if not '_charset_' parameter is provided. * @param request Request. * @param param Parameter name. * @param defaultValue Default value. * @return Parameter value or the default value if it is not set. */ public static @Nullable String get(@NotNull ServletRequest request, @NotNull String param, @Nullable String defaultValue) { String value = request.getParameter(param); if (value != null) { // convert encoding to UTF-8 if not form encoding parameter is set if (!hasFormEncodingParam(request)) { value = convertISO88591toUTF8(value); } return value; } else { return defaultValue; } }
/** * Returns a request parameter array.<br> * The method fixes problems with incorrect UTF-8 characters returned by the servlet engine. * All character data is converted from ISO-8859-1 to UTF-8. * @param request Request. * @param param Parameter name. * @return Parameter value array value or null if it is not set. */ public static String @Nullable [] getMultiple(@NotNull ServletRequest request, @NotNull String param) { String[] values = request.getParameterValues(param); if (values == null) { return null; } // convert encoding to UTF-8 if not form encoding parameter is set if (!hasFormEncodingParam(request)) { String[] convertedValues = new String[values.length]; for (int i = 0; i < values.length; i++) { if (values[i] != null) { convertedValues[i] = convertISO88591toUTF8(values[i]); } } return convertedValues; } else { return values; } }