Example usage for javax.servlet.http HttpServletRequest getParameterNames

List of usage examples for javax.servlet.http HttpServletRequest getParameterNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterNames.

Prototype

public Enumeration<String> getParameterNames();

Source Link

Document

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Usage

From source file:architecture.ee.web.util.ParamUtils.java

/**
* request String //from  w  w  w. j a v a2 s  .c o  m
* @param request
* @return
*/
public static void printParameter(HttpServletRequest request, Log log) {
    StringBuilder sb = new StringBuilder();
    Enumeration e = request.getParameterNames();

    sb.append("\n ==================== printParameter ====================");
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = request.getParameter(key);
        sb.append("\n ==== " + key + " : " + value + " ");
    }
    sb.append("\n ==================== printParameter ====================\n");

    //return sb.toString();
    log.debug(sb);
}

From source file:de.micromata.genome.logging.LogRequestParameterAttribute.java

/**
 * Fuer Logging gibt alle requestparameter in einer Zeile aus.
 *
 * @param request the request/*  w  w  w .j av a  2s  .  c o m*/
 * @param excludingKeys the excluding keys
 * @return the request for logging
 */
public static String getRequestForLogging(HttpServletRequest request, String... excludingKeys) {
    if (request == null || request.getParameterMap().isEmpty() == true) {
        return "<no params>";
    }

    StringBuilder sb = new StringBuilder();
    for (Enumeration<?> en = request.getParameterNames(); en.hasMoreElements() == true;) {
        String s = (String) en.nextElement();
        String[] values = request.getParameterValues(s);
        for (String v : values) {
            for (String exKey : excludingKeys) {
                if (StringUtils.equals(s, exKey) == true) {
                    v = "****";
                    break;
                }
            } // for
            sb.append(s).append("=").append(v).append("\n");
        }
    }
    return sb.toString();
}

From source file:net.shopxx.plugin.unionpayPayment.UnionpayPaymentPlugin.java

/**
 * ???//from   w w w  .  j a va2 s .co m
 * 
 * @param request
 * @return
 */
public static Map<String, String> getAllRequestParam(final HttpServletRequest request) {
    Map<String, String> res = new HashMap<String, String>();
    Enumeration<?> temp = request.getParameterNames();
    if (null != temp) {
        while (temp.hasMoreElements()) {
            String en = (String) temp.nextElement();
            String value = request.getParameter(en);
            res.put(en, value);
            // ???<?????>
            if (res.get(en) == null || "".equals(res.get(en))) {
                // System.out.println("======??===="+en);
                res.remove(en);
            }
        }
    }
    return res;
}

From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java

/**
 * Go through the request parameters and figure out which checkboxes are
 * selected./*from  w  w  w.ja va  2  s  .  com*/
 * 
 * @param startsWithValue
 *            A way to identify all the checkboxes. For example ckbox_.
 */
public static List checkboxesSelected(HttpServletRequest request, String startsWithValue) {
    List results = new ArrayList();

    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        if (parameterName.startsWith(startsWithValue)) {
            results.add(StringUtils.substringAfter(parameterName, startsWithValue));
        }
    }

    return results;
}

From source file:fr.paris.lutece.util.http.SecurityUtil.java

/**
 * Scan request parameters to see if there no malicious code.
 *
 * @param request The HTTP request/*from w  w  w .  j  a va  2 s  .com*/
 * @param strXssCharacters a String wich contain a list of Xss characters to check in strValue
 * @return true if all parameters don't contains any special characters
 */
public static boolean containsCleanParameters(HttpServletRequest request, String strXssCharacters) {
    String key;
    String[] values;

    Enumeration<String> e = request.getParameterNames();

    while (e.hasMoreElements()) {
        key = e.nextElement();
        values = request.getParameterValues(key);

        int length = values.length;

        for (int i = 0; i < length; i++) {
            if (SecurityUtil.containsXssCharacters(request, values[i], strXssCharacters)) {
                Logger logger = Logger.getLogger(LOGGER_NAME);
                logger.warn("SECURITY WARNING : INVALID REQUEST PARAMETERS" + dumpRequest(request));

                return false;
            }
        }
    }

    return true;
}

From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java

public static int getTargetPage(HttpServletRequest request) {
    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if (paramName.startsWith("_target")) {
            return Integer.parseInt(paramName.substring(7));
        }/*from   w w w  . j  a v  a  2 s .  c o m*/
    }
    return -1;
}

From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java

public static boolean hasParameter(HttpServletRequest request, String paramName) {
    for (Enumeration en = request.getParameterNames(); en.hasMoreElements();) {
        if (en.nextElement().equals(paramName))
            return true;
    }//  www  . j  a  va2s.c om
    return false;
}

From source file:com.bsb.cms.commons.web.MossActionUtils.java

/**
 * ?? ???<s:debug></s:debug> 
 * //from w  ww  .j av  a 2s .co m
 * @param req
 */
@SuppressWarnings("all")
@Deprecated
public static void print(HttpServletRequest req) {
    // Application
    Map<String, Object> parameters = new WeakHashMap<String, Object>();

    // attributes in scope RequestParameter
    for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        String[] v = req.getParameterValues(name);
        if (v.length == 1) {
            if (v[0].equals(""))
                continue;
            parameters.put(name, v[0]);
        } else
            parameters.put(name, v);
    }

    // attributes in scope Request
    for (Enumeration e = req.getAttributeNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        Object v = req.getAttribute(name);
        parameters.put(name, v);
    }

    // attributes in scope Session
    HttpSession session = req.getSession();
    for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        Object v = session.getAttribute(name);
        parameters.put(name, v);
    }

    Set keys = parameters.keySet();
    Iterator it = keys.iterator();
    String key;
    Object value;
    while (it.hasNext()) {
        key = (String) it.next();
        value = parameters.get(key);
        System.out.println("key:" + key + ", value:" + value);
    }

}

From source file:com.ziduye.base.web.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * // ww  w  .jav  a 2 s.c om
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(HttpServletRequest request, String prefix) {
    Validate.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;
}

From source file:com.tek271.reverseProxy.servlet.ProxyFilter.java

private static MultipartEntity getMultipartEntity(HttpServletRequest request) {
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    Enumeration<String> en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String name = en.nextElement();
        String value = request.getParameter(name);
        try {/*w  w w . java2s  .c  o  m*/
            if (name.equals("file")) {
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(10000000);// 10 Mo
                List items = upload.parseRequest(request);
                Iterator itr = items.iterator();
                while (itr.hasNext()) {
                    FileItem item = (FileItem) itr.next();
                    File file = new File(item.getName());
                    FileOutputStream fos = new FileOutputStream(file);
                    fos.write(item.get());
                    fos.flush();
                    fos.close();
                    entity.addPart(name, new FileBody(file, "application/zip"));
                }
            } else {
                entity.addPart(name, new StringBody(value.toString(), "text/plain", Charset.forName("UTF-8")));
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (FileUploadException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (FileNotFoundException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }

    return entity;

}