List of usage examples for javax.servlet ServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:org.mitre.medj.WebUtils.java
/** * Retrieves a parameter from a passed request. If the parameter is not * found, an NPE is thrown.//from w ww. j a va 2 s . c o m * * @param req Request object to look in * @param name the name of the field from the html * form * @return the value from the html form * corresponding to the name parameter * @exception NullPointerException thrown if the name was not in the html * form */ public static String getRequiredParameter(ServletRequest req, String name) throws NullPointerException { String ret = req.getParameter(name); if (ret == null) { throw new NullPointerException("This form requires a \"" + name + "\" parameter, which was missing from the submitted request."); } return ret; }
From source file:org.yes.cart.web.support.util.HttpUtil.java
private static void dumpParamsAndAttrs(final ServletRequest req, final StringBuilder stringBuilder) { final Enumeration parameterNames = req.getParameterNames(); while (parameterNames.hasMoreElements()) { final String key = (String) parameterNames.nextElement(); stringBuilder.append(MessageFormat.format("\nParameter {0}={1}", key, req.getParameter(key))); }//from w ww .j av a 2 s. com Enumeration attributeNames = req.getAttributeNames(); while (attributeNames.hasMoreElements()) { final String key = (String) attributeNames.nextElement(); stringBuilder.append(MessageFormat.format("\nAttribute {0}={1}", key, req.getAttribute(key))); } }
From source file:org.mitre.medj.WebUtils.java
/** * Gets the optionalParameter attribute of the WebUtils class * * @param req The servlet request object to pull it * out of./*w w w . j a va 2s. com*/ * @param name Name of the Parameter * @param defalt The default value (yes, defalt is * spelled incorrectly - default is a keyword * @return The optionalParameter value * @exception NullPointerException Description of the Exception */ public static String getOptionalParameter(ServletRequest req, String name, String defalt) throws NullPointerException { String ret = req.getParameter(name); if (ret == null) { ret = defalt; } return ret; }
From source file:com.redhat.rhn.common.util.ServletUtils.java
/** * Creates a encoded URL query string with the parameters from the given request. If the * request is a GET, then the returned query string will simply consist of the query * string from the request. If the request is a POST, the returned query string will * consist of the form variables./*from w w w . ja v a 2s . c o m*/ * * <br/><br/> * * <strong>Note</strong>: This method does not support multi-value parameters. * * @param request The request for which the query string will be generated. * * @return An encoded URL query string with the parameters from the given request. */ public static String requestParamsToQueryString(ServletRequest request) { StringBuffer queryString = new StringBuffer(); String paramName = null; String paramValue = null; Enumeration paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { paramName = (String) paramNames.nextElement(); paramValue = request.getParameter(paramName); queryString.append(encode(paramName)).append("=").append(encode(paramValue)).append("&"); } if (endsWith(queryString, '&')) { queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }
From source file:org.squale.welcom.taglib.field.util.LayoutUtils.java
/** * @param request la request/*ww w .j a va 2 s.c om*/ * @return la property frImproveStrutsTaglibLayoutPROPERTY_TO_CHOOSE */ public static String getPropertyToChoose(final ServletRequest request) { final String property = request.getParameter("frImproveStrutsTaglibLayoutPROPERTY_TO_CHOOSE"); if ((property != null) && (property.length() > 0)) { return property; } return null; }
From source file:com.github.dactiv.common.utils.ServletUtils.java
/** * ????ServletRequest?/*from w w w . j ava 2 s .c o m*/ * * @param request ServletRequest * @param name ??? * * @return List */ public static List<String> getParameterValues(ServletRequest request, String name) { List<String> list = new ArrayList<String>(); if (request == null || StringUtils.isEmpty(name)) { return list; } String[] values = request.getParameterValues(name); if (ArrayUtils.isNotEmpty(values)) { CollectionUtils.addAll(list, values); } else { String value = request.getParameter(name); if (StringUtils.isNotEmpty(value)) { values = StringUtils.splitByWholeSeparator(value, ","); } } if (values != null && values.length > 0) { CollectionUtils.addAll(list, values); } return list; }
From source file:org.jsecurity.web.WebUtils.java
/** * Convenience method that returns a request parameter value, first running it through * {@link StringUtils#clean(String)}./*from w w w . j a v a2 s . c om*/ * * @param request the servlet request. * @param paramName the parameter name. * @return the clean param value, or null if the param does not exist or is empty. */ public static String getCleanParam(ServletRequest request, String paramName) { return StringUtils.clean(request.getParameter(paramName)); }
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)); }/* w w w .j a v a2s . c om*/ 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:dk.netarkivet.archive.webinterface.BitpreserveFileState.java
/** * Extract the name of the replica (parameter Constants.BITARCHIVE_NAME_PARAM) and the type of update requested * (parameter Constants.UPDATE_TYPE_PARAM). The latter is set to to Constants.FIND_MISSING_FILES_OPTION if the * request is to update missing files, or to Constants.CHECKSUM_OPTION if the request is to update the checksum * information.// w ww . ja v a 2s. c o m * * @param context the current JSP context * @return an I18N string telling which type of update has just been initiated. * @throws ForwardedToErrorPage if an unknown bitarchive or update type is posted, or one of the two required * parameters are missing. * @throws ArgumentNotValid If the context is null. */ public static String processUpdateRequest(PageContext context) throws ArgumentNotValid, ForwardedToErrorPage { ArgumentNotValid.checkNotNull(context, "PageContext context"); ServletRequest request = context.getRequest(); String bitarchiveName = request.getParameter(Constants.BITARCHIVE_NAME_PARAM); if (bitarchiveName == null) { HTMLUtils.forwardWithErrorMessage(context, I18N, "errormsg;missing.parameter.0", Constants.BITARCHIVE_NAME_PARAM); throw new ForwardedToErrorPage("Parameter '" + Constants.BITARCHIVE_NAME_PARAM + "' not set"); } String updateTypeRequested = request.getParameter(Constants.UPDATE_TYPE_PARAM); if (updateTypeRequested == null) { HTMLUtils.forwardWithErrorMessage(context, I18N, "errormsg;missing.parameter.0", Constants.UPDATE_TYPE_PARAM); throw new ForwardedToErrorPage("Parameter '" + Constants.UPDATE_TYPE_PARAM + "' not set"); } if (!Replica.isKnownReplicaName(bitarchiveName)) { HTMLUtils.forwardWithErrorMessage(context, I18N, "errormsg;unknown.bitarchive.0", bitarchiveName); throw new ForwardedToErrorPage("Unknown replica: " + bitarchiveName); } Replica bitarchive = Replica.getReplicaFromName(bitarchiveName); Locale l = context.getResponse().getLocale(); String statusmessage = HTMLUtils.escapeHtmlValues( I18N.getString(l, "initiating;update.of.0.for.replica.1", updateTypeRequested, bitarchiveName)); if (updateTypeRequested.equalsIgnoreCase(Constants.FIND_MISSING_FILES_OPTION)) { // Start new thread for findmissing files action. new BitpreservationUpdateThread(bitarchive, BitpreservationUpdateType.FINDMISSING).start(); return statusmessage; } else if (updateTypeRequested.equalsIgnoreCase(Constants.CHECKSUM_OPTION)) { // Start new thread for finding corrupt files action. new BitpreservationUpdateThread(bitarchive, BitpreservationUpdateType.CHECKSUM).start(); return statusmessage; } else { HTMLUtils.forwardWithErrorMessage(context, I18N, "errormsg;unknown.filestatus.update.type.0", updateTypeRequested); throw new ForwardedToErrorPage("Unknown filestatus update type: " + bitarchiveName); } }
From source file:com.redhat.rhn.frontend.taglibs.list.DataSetManipulator.java
/** * Returns the pagination param (|<, <, >, >|) that was selected * returns null if no pagination action was selected. * @param request the http servlet request * @param uniqueName the unique name of list to check * @return the selected pagination param or null if none was selected. *///from w w w . ja v a2s . c o m static String getPaginationParam(ServletRequest request, String uniqueName) { for (int x = 0; x < LINK_PREFIXES.length; x++) { String imgLink = "list_" + uniqueName + "_page" + LINK_PREFIXES[x]; if (request.getParameter(imgLink) != null) { return "list_" + uniqueName + "_page" + LINK_PREFIXES[x]; } } return null; }