本文整理汇总了Java中javax.servlet.ServletRequest.getParameterNames方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.getParameterNames方法的具体用法?Java ServletRequest.getParameterNames怎么用?Java ServletRequest.getParameterNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getParameterNames方法的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: getTargetPage
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Return the target page specified in the request.
* @param request current servlet request
* @param paramPrefix the parameter prefix to check for
* (e.g. "_target" for parameters like "_target1" or "_target2")
* @param currentPage the current page, to be returned as fallback
* if no target page specified
* @return the page specified in the request, or current page if not found
*/
public static int getTargetPage(ServletRequest request, String paramPrefix, int currentPage) {
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
if (paramName.startsWith(paramPrefix)) {
for (int i = 0; i < WebUtils.SUBMIT_IMAGE_SUFFIXES.length; i++) {
String suffix = WebUtils.SUBMIT_IMAGE_SUFFIXES[i];
if (paramName.endsWith(suffix)) {
paramName = paramName.substring(0, paramName.length() - suffix.length());
}
}
return Integer.parseInt(paramName.substring(paramPrefix.length()));
}
}
return currentPage;
}
示例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.
*
* 返回的结果的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;
}
示例5: 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;
}
示例6: introspect
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static void introspect(Object bean, ServletRequest request)
throws JasperException
{
Enumeration<String> e = request.getParameterNames();
while ( e.hasMoreElements() ) {
String name = e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
示例7: 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;
}
示例8: introspect
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static void introspect(Object bean, ServletRequest request)
throws JasperException
{
Enumeration e = request.getParameterNames();
while ( e.hasMoreElements() ) {
String name = (String) e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
示例9: 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;
}
示例10: introspect
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public static void introspect(Object bean, ServletRequest request) throws JasperException {
Enumeration<String> e = request.getParameterNames();
while (e.hasMoreElements()) {
String name = e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
示例11: 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);
}