Example usage for javax.servlet ServletRequest getParameter

List of usage examples for javax.servlet ServletRequest getParameter

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getParameter.

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Check if a specific input type="submit" parameter was sent in the request,
 * either via a button (directly with name) or via an image (name + ".x" or
 * name + ".y")./*from   w w w.j a  va 2 s .  c o m*/
 * @param request current HTTP request
 * @param name name of the parameter
 * @return if the parameter was sent
 * @see #SUBMIT_IMAGE_SUFFIXES
 */
public static boolean hasSubmitParameter(ServletRequest request, String name) {
    Assert.notNull(request, "Request must not be null");
    if (request.getParameter(name) != null) {
        return true;
    }
    for (String suffix : SUBMIT_IMAGE_SUFFIXES) {
        if (request.getParameter(name + suffix) != null) {
            return true;
        }
    }
    return false;
}

From source file:org.jahia.data.viewhelper.principal.PrincipalViewHelper.java

/**
 * Get the user search result from the parameter form given by the request.
 * If the form is not in the request then all the Jahia users will be search.
 *
 * @param request the request that should contain the HTML formular with the
 *                following fields :/*from  ww  w  .ja va 2s  .c  o  m*/
 *                - searchString
 *                - searchIn
 *                - properties
 *                - storedOn
 *                - providers
 * @return a Properties object that contain the search criterium
 */
public static Set<JCRUserNode> getSearchResult(ServletRequest request) {

    String searchString = request.getParameter("searchString");
    final String searchIn = request.getParameter("searchIn");
    final String[] searchInProps = request.getParameterValues("properties");
    final String storedOn = request.getParameter("storedOn");
    final String[] providers = request.getParameterValues("providers");

    return getSearchResult(searchIn, null, searchString, searchInProps, storedOn, providers);
}

From source file:org.jahia.data.viewhelper.principal.PrincipalViewHelper.java

/**
 * Get the group search result from the parameter form given by the request.
 * If the form is not in the request then all the Jahia groups will be search.
 *
 * @param request the request that should contain the HTML formular with the
 *                following fields :/* w  ww  .j a  v a2  s .  c o  m*/
 *                - searchString
 *                - searchIn
 *                - properties
 *                - storedOn
 *                - providers
 * @param siteKey  The site ID containing the principal to search
 * @return a Properties object that contain the search criterium
 */
public static Set<JCRGroupNode> getGroupSearchResult(ServletRequest request, String siteKey) {

    String searchString = request.getParameter("searchString");
    final String searchIn = request.getParameter("searchIn");
    final String[] searchInProps = request.getParameterValues("properties");
    final String storedOn = request.getParameter("storedOn");
    final String[] providers = request.getParameterValues("providers");

    return getGroupSearchResult(searchIn, siteKey, searchString, searchInProps, storedOn, providers);
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static String getRequestParameter(String name) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ServletRequest request = (ServletRequest) facesContext.getExternalContext().getRequest();

    return request.getParameter(name);
}

From source file:dk.netarkivet.archive.webinterface.BitpreserveFileState.java

/**
 * Processes a checksum request./*  w w  w.j a v a2  s . c  o  m*/
 * <p>
 * The name of a bitarchive must always be given in parameter Constants.BITARCHIVE_NAME_PARAM.
 * <p>
 * If parameter Constants.FILENAME_PARAM is given, file info for that file will be returned, and all actions will
 * work on that file.
 * <p>
 * If parameter Constants.FIX_ADMIN_CHECKSUM_PARAM is given, the admin data checksum will be fixed for the file.
 * <p>
 * If parameter Constants.CREDENTIALS and Constants.CHECKSUM_PARAM is given, removes and reuploads a file with that
 * checksum in the given bitarchive, using the credentials for authorisation.
 *
 * @param res the result object. This is updated with result information, and expected to be printed to the
 * resulting page.
 * @param context the current JSP pagecontext.
 * @return The file preservation state for a file, if a filename is given in the request. Null otherwise.
 * @throws ArgumentNotValid If the context or res is null.
 */
public static PreservationState processChecksumRequest(StringBuilder res, PageContext context)
        throws ArgumentNotValid {
    ArgumentNotValid.checkNotNull(res, "StringBuilder res");
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    ServletRequest request = context.getRequest();
    Locale l = context.getResponse().getLocale();
    HTMLUtils.forwardOnIllegalParameter(context, Constants.BITARCHIVE_NAME_PARAM, Replica.getKnownNames());
    String bitarchiveName = request.getParameter(Constants.BITARCHIVE_NAME_PARAM);
    Replica bitarchive = Replica.getReplicaFromName(bitarchiveName);
    String filename = request.getParameter(Constants.FILENAME_PARAM);
    String fixadminchecksum = request.getParameter(Constants.FIX_ADMIN_CHECKSUM_PARAM);
    String credentials = request.getParameter(Constants.CREDENTIALS_PARAM);
    String checksum = request.getParameter(Constants.CHECKSUM_PARAM);

    // Parameter validation. Get filename. Complain about missing filename
    // if we are trying to do actions.
    if (filename == null) { // param "file" not set - no action to take
        if (fixadminchecksum != null || credentials != null || checksum != null) {
            // Only if an action was intended do we complain about
            // a missing file.
            res.append(I18N.getString(l, "errormsg;lack.name.for.file.to.be.corrected.in.0", bitarchiveName));
        }
        return null;
    }

    // At this point we know that the parameter filename is given.
    // Now we check for actions.
    ActiveBitPreservation preserve = ActiveBitPreservationFactory.getInstance();
    if (fixadminchecksum != null) {
        // Action to fix admin.data checksum.
        preserve.changeStateForAdminData(filename);
        res.append(I18N.getString(l, "file.0.now.has.correct.checksum.in.admin.data", filename));
        res.append("<br/>");
    } else if (checksum != null || credentials != null) {
        // Action to replace a broken file with a correct file.
        // Both parameters must be given.
        if (checksum == null) { // param CHECKSUM_PARAM not set
            res.append(I18N.getString(l, "errormsg;lack.checksum.for.corrupted.file.0", filename));
            res.append("<br/>");
        } else if (credentials == null) { // param CREDENTIALS_PARAM not set
            res.append(I18N.getString(l, "errormsg;lacking.privileges.to.correct.in.replica"));
            res.append("<br/>");
        } else {
            // Parameters are correct. Fix the file and report result.
            try {
                preserve.replaceChangedFile(bitarchive, filename, credentials, checksum);
                res.append(I18N.getString(l, "file.0.has.been.replaced.in.1", filename, bitarchive));
                res.append("<br/>");
            } catch (Exception e) {
                res.append(I18N.getString(l, "errormsg;attempt.at.restoring.0.in.replica" + ".at.1.failed",
                        filename, bitarchive));
                res.append("<br/>");
                res.append(e.getMessage());
                res.append("<br/>");
                log.warn("Attempt at restoring '" + filename + "' in bitarchive on replica '" + bitarchive
                        + "' failed", e);
            }
        }
    }

    return preserve.getPreservationState(filename);
}

From source file:org.tsugi.jpa.LTIRequest.java

/**
 * @param request the incoming request/*from  w ww .  j a  v a2 s  .c o  m*/
 * @return true if this is a valid LTI request
 */
public static boolean isLTIRequest(ServletRequest request) {
    boolean valid = false;
    String ltiVersion = StringUtils.trimToNull(request.getParameter(LTI_VERSION));
    String ltiMessageType = StringUtils.trimToNull(request.getParameter(LTI_MESSAGE_TYPE));
    if (ltiMessageType != null && ltiVersion != null) {
        boolean goodMessageType = LTI_MESSAGE_TYPE_BASIC.equals(ltiMessageType)
                || LTI_MESSAGE_TYPE_PROXY_REG.equals(ltiMessageType);
        boolean goodLTIVersion = LTI_VERSION_1P0.equals(ltiVersion) || LTI_VERSION_2P0.equals(ltiVersion);
        valid = goodMessageType && goodLTIVersion;
    }
    // resource_link_id is also required
    return valid;
}

From source file:org.rhq.enterprise.gui.util.WebUtility.java

public static PageControl getPageControl(ServletRequest request, String postfix) {
    // TODO GH: Add a mechanism to persist these settings in user preferences and default from there
    if (postfix == null) {
        postfix = "";
    }/*  w  w  w .j a v a  2 s . co m*/

    int pageNumber = getOptionalIntRequestParameter(request, ParamConstants.PAGENUM_PARAM + postfix,
            DefaultConstants.PAGENUM_DEFAULT);
    int pageSize = getOptionalIntRequestParameter(request, ParamConstants.PAGESIZE_PARAM + postfix,
            DefaultConstants.PAGESIZE_DEFAULT);

    // Make sure the user doesn't go around us and create huge pages
    pageSize = Math.min(pageSize, PageControl.SIZE_MAX);

    String sortOrderString = request.getParameter(ParamConstants.SORTORDER_PARAM + postfix);
    PageOrdering sortOrder = PageOrdering.ASC;
    if ((sortOrderString != null) && (sortOrderString.length() > 0)) {
        try {
            sortOrder = PageOrdering.valueOf(sortOrderString.toUpperCase());
        } catch (RuntimeException e) {
            throw new RuntimeException("Request parameter '" + ParamConstants.SORTORDER_PARAM + postfix
                    + "' has an invalid value ('" + sortOrderString
                    + "') - valid values are 'asc' or 'desc' (case-insensitive).");
        }
    }

    String sortColumn = getOptionalRequestParameter(request, ParamConstants.SORTCOL_PARAM + postfix, null);
    if (sortColumn != null) {
        if (sortColumn.contains(" ") && !sortColumn.toLowerCase().endsWith(" desc")) {
            throw new RuntimeException(
                    "This app is not vulnerable to SQL-injection attacks. Thanks for playing.");
        }
    }

    return new PageControl(pageNumber, pageSize, new OrderingField(sortColumn, sortOrder));
}

From source file:de.escidoc.core.aa.servlet.Login.java

/**
 * Retrieves the decoded parameter target from the provided request.
 *
 * @param request The http request to retrieve the parameter from.
 * @return Returns the decoded parameter target or {@code null}.
 * @throws MissingParameterException Thrown if a mandatory parameter is missing.
 */// w  w  w  .  j a  v  a  2 s.c  o m
private static String retrieveDecodedTarget(final ServletRequest request) throws MissingParameterException {

    try {
        final String targetParameter = request.getParameter(EscidocServlet.PARAM_TARGET);
        if (targetParameter != null) {
            return URLDecoder.decode(targetParameter, EscidocServlet.ENCODING);
        } else {
            throw new MissingParameterException("No target parameter provided in URL");
        }
    } catch (final UnsupportedEncodingException e) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("Error on retriving decoded target.");
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Error on retriving decoded target.", e);
        }
        return "";
    }
}

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  .jav a  2s .  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:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Checks that the given parameters exist and are not empty. If any of them are missing or empty, forwards to the
 * error page and throws ForwardedToErrorPage. A parameter with only whitespace is considered empty.
 *
 * @param context The context of the current JSP page
 * @param parameters List of parameters that must exist and be non-empty
 * @throws IOFailure If the forward fails
 * @throws ForwardedToErrorPage if a parameter was missing or empty
 *//*w ww.  j ava 2 s.  c  o m*/
public static void forwardOnEmptyParameter(PageContext context, String... parameters) {
    // Note that we may not want to be to strict here
    // as otherwise information could be lost.
    ArgumentNotValid.checkNotNull(context, "context");
    ArgumentNotValid.checkNotNull(parameters, "parameters");

    forwardOnMissingParameter(context, parameters);
    ServletRequest request = context.getRequest();
    for (String parameter : parameters) {
        String value = request.getParameter(parameter);
        if (value.trim().length() == 0) {
            forwardWithErrorMessage(context, I18N, "errormsg;empty.parameter.0", parameter);
            throw new ForwardedToErrorPage("Empty parameter '" + parameter + "'");
        }
    }
}