List of usage examples for javax.servlet ServletRequest getParameterNames
public Enumeration<String> getParameterNames();
Enumeration
of String
objects containing the names of the parameters contained in this request. From source file:com.netspective.sparx.util.HttpUtils.java
public static String appendParams(ServletRequest req, String url, String paramNames) { StringBuffer result = new StringBuffer(url); boolean hasQueryChar = url.indexOf('?') >= 0; if (paramNames.equals("*")) { int i = 0; for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) { String paramName = (String) e.nextElement(); String paramValue = req.getParameter(paramName); if (paramValue != null) { if (i > 0 || hasQueryChar) result.append("&"); else result.append("?"); result.append(paramName); result.append("="); result.append(URLEncoder.encode(paramValue)); }//www . j a v a2 s . c o m i++; } } else { String[] retainParams = TextUtils.getInstance().split(paramNames, ",", true); for (int i = 0; i < retainParams.length; i++) { String paramName = retainParams[i]; String paramValue = req.getParameter(paramName); if (paramValue != null) { if (i > 0 || hasQueryChar) result.append("&"); else result.append("?"); result.append(paramName); result.append("="); result.append(URLEncoder.encode(paramValue)); } } } return result.toString(); }
From source file:edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils.java
public static Properties loadPropertiesFromRequest(Properties current, ServletRequest req) { if (req == null || current == null) { log.error("UtilBean.loadPropertiesFromRequest() exiting because of null input"); return current; }//from w ww .j av a 2 s. co m // try{ // current.store(System.out,"header from store"); // }catch( Exception ex){ // log.debug("exception in utilBean"); // } Enumeration names = req.getParameterNames(); String value = null; String name = null; while (names.hasMoreElements()) { name = (String) names.nextElement(); // log.debug("parameter name: " + name); value = req.getParameter(name); if (value != null) { // log.debug("*** current set " + name + " to " + value ); current.setProperty(name, value); } } return current; }
From source file:org.jruby.rack.mock.WebUtils.java
/** * 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// w ww. j a v a 2 s.com * @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; }
From source file:org.jruby.rack.mock.WebUtils.java
/** * 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 *//*from w ww.j a va 2 s . co m*/ 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; }
From source file:org.rhq.enterprise.gui.legacy.util.RequestUtils.java
public static String dumpRequestParamsToString(ServletRequest request, boolean html) { StringBuffer output = new StringBuffer(); if (html) {/*from w w w .j av a 2s . c o m*/ output.append("<ol>\n"); } for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String[] values = request.getParameterValues(key); if (html) { output.append("<li>"); } output.append("'" + key + "' = "); for (int i = 0; i < (values.length - 1); i++) { output.append("'" + values[i] + "', "); } output.append("'" + values[values.length - 1] + "'"); output.append("\n"); } if (html) { output.append("</ol>\n"); } return output.toString(); }
From source file:org.hyperic.hq.ui.util.RequestUtils.java
public static String dumpRequestParamsToString(ServletRequest request, boolean html) { StringBuffer output = new StringBuffer(); if (html)/* ww w. j a va 2s . co m*/ output.append("<ol>\n"); for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String[] values = request.getParameterValues(key); if (html) output.append("<li>"); output.append(key + " = "); for (int i = 0; i < values.length; i++) { output.append(values[i] + "\n "); } } if (html) output.append("</ol>\n"); return output.toString(); }
From source file:CheckFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Enumeration params = request.getParameterNames(); boolean rejected = false; while (params.hasMoreElements()) { if (isEmpty(request.getParameter((String) params.nextElement()))) { reject(request, response);/*w w w .j a v a2s . co m*/ rejected = true; } } if (!rejected) chain.doFilter(request, response); }
From source file:com.threeti.proxy.RequestFilter.java
private String getParams(ServletRequest req) { StringBuffer params = new StringBuffer(); Enumeration<String> keys = req.getParameterNames(); while (keys.hasMoreElements()) { String key = keys.nextElement(); try {//from ww w . ja va 2 s. c om // params.append(key).append("=").append(URLEncoder.encode(req.getParameter(key), "UTF-8")).append("&"); params.append(key).append("=").append(req.getParameter(key)).append("&"); // if("".equals(req.getParameter(key))){ // params.append(key); // }else{ // // } } catch (Exception e) { e.printStackTrace(); } } System.out.println(params.toString()); return params.toString(); }
From source file:CheckFilter.java
private void reject(ServletRequest request, ServletResponse response) throws IOException, ServletException { request.setAttribute("errorMsg", "Please make sure to provide a valid value for all of the text fields."); Enumeration params = request.getParameterNames(); String paramN = null;//from w w w .j a v a 2 s . c o m while (params.hasMoreElements()) { paramN = (String) params.nextElement(); request.setAttribute(paramN, request.getParameter(paramN)); } RequestDispatcher dispatcher = request.getRequestDispatcher("/form.jsp"); dispatcher.forward(request, response); }
From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java
/** * Returns a link containing the URL + ALL the parameters of the * request query string minus the sort links, and the alpha link + * the additional params passed in the paramsToAdd map. The resulting * string is urlEncode'd with & encoded as & so it can be used * in a href directly./* www . ja v a2s .com*/ * * @param request the Servlet Request * @param listName the current list name * @param paramsToAdd the params you might want to append to the url * for example makeSortLink passes in sortByLabel * while alpha bar passes in params that are specific to it. * @param paramsToIgnore params to not include that would be normally * @return a link containing the URL + (OtherParams - Sort - Alpha) + paramsToAdd */ public static String makeParamsLink(ServletRequest request, String listName, Map<String, String> paramsToAdd, List<String> paramsToIgnore) { String url = (String) request.getAttribute(ListTagHelper.PARENT_URL); String sortByLabel = makeSortByLabel(listName); String sortByDir = makeSortDirLabel(listName); String alphaKey = AlphaBarHelper.makeAlphaKey(listName); StringBuilder params = new StringBuilder(); if (url.indexOf('?') < 0) { params.append("?"); } else if (url.indexOf('?') != url.length() - 1) { url += "&"; } for (Enumeration<String> en = request.getParameterNames(); en.hasMoreElements();) { String paramName = en.nextElement(); if (!sortByLabel.equals(paramName) && !sortByDir.equals(paramName) && !alphaKey.equals(paramName) && !paramsToIgnore.contains(paramName)) { if (params.length() > 1) { params.append("&"); } params.append(StringUtil.urlEncode(paramName)).append("=") .append(StringUtil.urlEncode(request.getParameter(paramName))); } } for (String key : paramsToAdd.keySet()) { if (params.length() > 1) { params.append("&"); } params.append(StringUtil.urlEncode(key)).append("=").append(StringUtil.urlEncode(paramsToAdd.get(key))); } return url + params.toString(); }