本文整理汇总了Java中javax.servlet.ServletRequest.getParameterValues方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.getParameterValues方法的具体用法?Java ServletRequest.getParameterValues怎么用?Java ServletRequest.getParameterValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getParameterValues方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParametersStartingWith
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Return a map containing all parameters with the given prefix.
* Maps single values to String and multiple values to String array.
* <p>For example, with a prefix of "spring_", "spring_param1" and
* "spring_param2" result in a Map with "param1" and "param2" as keys.
* @param request HTTP request in which to look for parameters
* @param prefix the beginning of parameter names
* (if this is null or the empty string, all parameters will match)
* @return map containing request parameters <b>without the prefix</b>,
* containing either a String or a String array as values
* @see javax.servlet.ServletRequest#getParameterNames
* @see javax.servlet.ServletRequest#getParameterValues
* @see javax.servlet.ServletRequest#getParameterMap
*/
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
Assert.notNull(request, "Request must not be null");
Enumeration<String> paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
if (prefix == null) {
prefix = "";
}
while (paramNames != null && paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
if ("".equals(prefix) || paramName.startsWith(prefix)) {
String unprefixed = paramName.substring(prefix.length());
String[] values = request.getParameterValues(paramName);
if (values == null || values.length == 0) {
// Do nothing, no values found at all.
}
else if (values.length > 1) {
params.put(unprefixed, values);
}
else {
params.put(unprefixed, values[0]);
}
}
}
return params;
}
示例2: getParametersStartingWith
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* 取得带相同前缀的Request Parameters.
*
* 返回的结果的Parameter名已去除前缀.
*/
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
AssertUtils.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
if (prefix == null) {
prefix = "";
}
while (paramNames != null && paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if ("".equals(prefix) || paramName.startsWith(prefix)) {
String unprefixed = paramName.substring(prefix.length());
String[] values = request.getParameterValues(paramName);
if (values == null || values.length == 0) {
// Do nothing, no values found at all.
} else if (values.length > 1) {
params.put(unprefixed, values);
} else {
params.put(unprefixed, values[0]);
}
}
}
return params;
}
示例3: getParametersStartingWith
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* 取得带相同前缀的Request Parameters.
*
* 返回的结果的Parameter名已去除前缀.
*/
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
AssertUtils.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
if (prefix == null) {
prefix = "";
}
while (paramNames != null && paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if ("".equals(prefix) || paramName.startsWith(prefix)) {
String unprefixed = paramName.substring(prefix.length());
String[] values = request.getParameterValues(paramName);
if (values == null || values.length == 0) {
// Do nothing, no values found at all.
} else if (values.length > 1) {
params.put(unprefixed, values);
} else {
params.put(unprefixed, values[0]);
}
}
}
return params;
}
示例4: getParametersStartingWith
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* 取得带相同前缀的Request Parameters, copy from spring WebUtils.
* <p>
* 返回的结果的Parameter名已去除前缀.
*/
@SuppressWarnings("rawtypes")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
Validate.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
String pre = prefix;
if (pre == null) {
pre = "";
}
while (paramNames != null && paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if ("".equals(pre) || paramName.startsWith(pre)) {
String unprefixed = paramName.substring(pre.length());
String[] values = request.getParameterValues(paramName);
if (values == null || values.length == 0) {
values = new String[]{};
// Do nothing, no values found at all.
} else if (values.length > 1) {
params.put(unprefixed, values);
} else {
params.put(unprefixed, values[0]);
}
}
}
return params;
}
示例5: getParametersStartingWith
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* 取得带相同前缀的Request Parameters. 返回的结果的Parameter名已去除前缀.
*
* @param request
* HttpServletRequest
* @param prefix
* String
* @return Map
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> getParametersStartingWith(
ServletRequest request, String prefix) {
Assert.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
String thePrefix = (prefix == null) ? "" : prefix;
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if ("".equals(thePrefix) || paramName.startsWith(thePrefix)) {
String unprefixed = paramName.substring(thePrefix.length());
String[] values = request.getParameterValues(paramName);
if ((values == null) || (values.length == 0)) {
// Do nothing, no values found at all.
continue;
}
if (values.length > 1) {
params.put(unprefixed, values);
} else {
params.put(unprefixed, values[0]);
}
}
}
return params;
}
示例6: getParametersStartingWith
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* 取得带相同前缀的Request Parameters, copy from spring WebUtils.
*
* 返回的结果的Parameter名已去除前缀.
*/
@SuppressWarnings("rawtypes")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
Validate.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map<String, Object> params = new TreeMap<String, Object>();
String pre = prefix;
if (pre == null) {
pre = "";
}
while (paramNames != null && paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if ("".equals(pre) || paramName.startsWith(pre)) {
String unprefixed = paramName.substring(pre.length());
String[] values = request.getParameterValues(paramName);
if (values == null || values.length == 0) {
values = new String[]{};
// Do nothing, no values found at all.
} else if (values.length > 1) {
params.put(unprefixed, values);
} else {
params.put(unprefixed, values[0]);
}
}
}
return params;
}
示例7: doFilter
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Time the processing that is performed by all subsequent filters in the
* current filter stack, including the ultimately invoked servlet.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (filterConfig == null)
return;
// Render the generic servlet request properties
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
writer.println("Request Received at " +
(new Timestamp(System.currentTimeMillis())));
writer.println(" characterEncoding=" + request.getCharacterEncoding());
writer.println();
Enumeration names = request.getParameterNames();
writer.println( "----------------parameters-----------" );
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
writer.print(" " + name + "=");
String values[] = request.getParameterValues(name);
for (int i = 0; i < values.length; i++) {
if (i > 0)
writer.print(", ");
writer.print(values[i]);
}
writer.println();
}
// writer.println(" protocol=" + request.getProtocol());
// writer.println(" remoteAddr=" + request.getRemoteAddr());
// writer.println(" remoteHost=" + request.getRemoteHost());
// writer.println(" scheme=" + request.getScheme());
// writer.println(" serverName=" + request.getServerName());
// writer.println(" serverPort=" + request.getServerPort());
// writer.println(" isSecure=" + request.isSecure());
// Render the HTTP servlet request properties
if (request instanceof HttpServletRequest) {
writer.println("---------------------------------------------");
HttpServletRequest hrequest = (HttpServletRequest) request;
//writer.println(" contextPath=" + hrequest.getContextPath());
// names = hrequest.getHeaderNames();
// while (names.hasMoreElements()) {
// String name = (String) names.nextElement();
// String value = hrequest.getHeader(name);
// writer.println(" header=" + name + "=" + value);
// }
//writer.println(" method=" + hrequest.getMethod());
writer.println(" pathInfo=" + hrequest.getPathInfo());
writer.println(" queryString=" + hrequest.getQueryString());
//writer.println(" remoteUser=" + hrequest.getRemoteUser());
//writer.println("requestedSessionId=" +
// hrequest.getRequestedSessionId());
writer.println(" requestURI=" + hrequest.getRequestURI());
writer.println(" servletPath=" + hrequest.getServletPath());
}
writer.println("=============================================");
System.out.println( sw.getBuffer().toString() );
// Log the resulting string
writer.flush();
filterConfig.getServletContext().log(sw.getBuffer().toString());
// Pass control on to the next filter
chain.doFilter(request, response);
}
示例8: introspecthelper
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static void introspecthelper(Object bean, String prop,
String value, ServletRequest request,
String param, boolean ignoreMethodNF)
throws JasperException {
Method method = null;
Class<?> type = null;
Class<?> propertyEditorClass = null;
try {
java.beans.BeanInfo info
= java.beans.Introspector.getBeanInfo(bean.getClass());
if ( info != null ) {
java.beans.PropertyDescriptor pd[]
= info.getPropertyDescriptors();
for (int i = 0 ; i < pd.length ; i++) {
if ( pd[i].getName().equals(prop) ) {
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
propertyEditorClass = pd[i].getPropertyEditorClass();
break;
}
}
}
if ( method != null ) {
if (type.isArray()) {
if (request == null) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.setproperty.noindexset"));
}
Class<?> t = type.getComponentType();
String[] values = request.getParameterValues(param);
//XXX Please check.
if(values == null) return;
if(t.equals(String.class)) {
method.invoke(bean, new Object[] { values });
} else {
createTypedArray (prop, bean, method, values, t,
propertyEditorClass);
}
} else {
if(value == null || (param != null && value.equals(""))) return;
Object oval = convert(prop, value, type, propertyEditorClass);
if ( oval != null )
method.invoke(bean, new Object[] { oval });
}
}
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
if (!ignoreMethodNF && (method == null)) {
if (type == null) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.noproperty",
prop,
bean.getClass().getName()));
} else {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.nomethod.setproperty",
prop,
type.getName(),
bean.getClass().getName()));
}
}
}
示例9: getCallback
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
protected String getCallback(ServletRequest req)
{
return req.getParameterValues(jsonp)[0];
}
示例10: internalIntrospecthelper
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
private static void internalIntrospecthelper(Object bean, String prop,
String value, ServletRequest request,
String param, boolean ignoreMethodNF)
throws JasperException
{
Method method = null;
Class type = null;
Class propertyEditorClass = null;
try {
java.beans.BeanInfo info
= java.beans.Introspector.getBeanInfo(bean.getClass());
if ( info != null ) {
java.beans.PropertyDescriptor pd[]
= info.getPropertyDescriptors();
for (int i = 0 ; i < pd.length ; i++) {
if ( pd[i].getName().equals(prop) ) {
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
propertyEditorClass = pd[i].getPropertyEditorClass();
break;
}
}
}
if ( method != null ) {
if (type.isArray()) {
if (request == null) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.setproperty.noindexset"));
}
Class t = type.getComponentType();
String[] values = request.getParameterValues(param);
//XXX Please check.
if(values == null) return;
if(t.equals(String.class)) {
method.invoke(bean, new Object[] { values });
} else {
Object tmpval = null;
createTypedArray (prop, bean, method, values, t,
propertyEditorClass);
}
} else {
if(value == null || (param != null && value.equals(""))) return;
Object oval = convert(prop, value, type, propertyEditorClass);
if ( oval != null )
method.invoke(bean, new Object[] { oval });
}
}
} catch (Exception ex) {
throw new JasperException(ex);
}
if (!ignoreMethodNF && (method == null)) {
if (type == null) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.noproperty",
prop,
bean.getClass().getName()));
} else {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.nomethod.setproperty",
prop,
type.getName(),
bean.getClass().getName()));
}
}
}
示例11: introspecthelper
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static void introspecthelper(Object bean, String prop, String value, ServletRequest request, String param,
boolean ignoreMethodNF) throws JasperException {
Method method = null;
Class<?> type = null;
Class<?> propertyEditorClass = null;
try {
java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(bean.getClass());
if (info != null) {
java.beans.PropertyDescriptor pd[] = info.getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(prop)) {
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
propertyEditorClass = pd[i].getPropertyEditorClass();
break;
}
}
}
if (method != null) {
if (type.isArray()) {
if (request == null) {
throw new JasperException(Localizer.getMessage("jsp.error.beans.setproperty.noindexset"));
}
Class<?> t = type.getComponentType();
String[] values = request.getParameterValues(param);
// XXX Please check.
if (values == null)
return;
if (t.equals(String.class)) {
method.invoke(bean, new Object[] { values });
} else {
createTypedArray(prop, bean, method, values, t, propertyEditorClass);
}
} else {
if (value == null || (param != null && value.equals("")))
return;
Object oval = convert(prop, value, type, propertyEditorClass);
if (oval != null)
method.invoke(bean, new Object[] { oval });
}
}
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
if (!ignoreMethodNF && (method == null)) {
if (type == null) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.noproperty", prop, bean.getClass().getName()));
} else {
throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod.setproperty", prop,
type.getName(), bean.getClass().getName()));
}
}
}