Example usage for javax.servlet.http HttpServletRequest getParameter

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest 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:azkaban.server.HttpRequestUtils.java

/**
 * Checks for the existance of the parameter in the request
 *
 * @param request/*  w  ww. j av a 2 s .  co m*/
 * @param param
 * @return
 */
public static boolean hasParam(HttpServletRequest request, String param) {
    return request.getParameter(param) != null;
}

From source file:com.liusoft.dlog4j.util.RequestUtils.java

/**
 * ?????//from  www.  j av  a  2s. c o m
 * @param param
 * @param defaultValue
 * @return
 */
public static String getParam(HttpServletRequest req, String param, String defaultValue) {
    String value = req.getParameter(param);
    return (StringUtils.isEmpty(value)) ? defaultValue : value;
}

From source file:net.sf.ginp.util.GinpUtil.java

/**
 * Parse an integer from a string and handle exceptions gracefully.
 * @param req the servlet request to get the parameter from
 * @param param the name of the parameter
 * @param defaultVal the default value if parsing fails
 * @return the parsed value or the default if parsing failed
 *///from   w w  w  .j av  a2s .  co  m
public static int parseInteger(final HttpServletRequest req, final String param, final int defaultVal) {
    if (req.getParameter(param) == null) {
        return defaultVal;
    }

    try {
        return new Integer(req.getParameter(param)).intValue();
    } catch (Exception ex) {
        log.error("An error occurred trying to parse the http parameter " + param
                + " to an int in the requested url " + req.getRequestURL());
    }

    return defaultVal;
}

From source file:gov.nih.nci.caarray.web.fileupload.MonitoredMultiPartRequest.java

/**
 * Retrieves the identifier for the current upload request.
 * @param request the current HTTP request
 * @return an identifier used to refer to this upload when checking for progress
 *//*from   w ww.  j a v a 2s.  c  o m*/
public static String getUploadKey(HttpServletRequest request) {
    String uploadId = request.getParameter(UPLOAD_ID_ATTRIBUTE);
    if (uploadId == null) {
        uploadId = StringUtils.defaultString((String) request.getAttribute(UPLOAD_ID_ATTRIBUTE));
    }
    return ProgressMonitor.SESSION_PROGRESS_MONITOR + uploadId;
}

From source file:info.magnolia.module.servletsanity.support.ServletAssert.java

public static void assertParameter(HttpServletRequest request, String name, String value) throws IOException {
    if (!StringUtils.equals(request.getParameter(name), value)) {
        append("ERROR Parameter [" + name + "] is incorrect [" + request.getParameter(name)
                + "] expected it to be [" + value + "]");
    } else {//  ww w.ja v a 2 s  . c  o m
        append("PASSED Parameter [" + name + "] is correct");
    }
}

From source file:ru.org.linux.csrf.CSRFProtectionService.java

/**
 * Check if user is authorized for request
 * @param request//from   w  w w  . j a v  a 2s . c o m
 * @return true when ok, false when not authorized
 */
public static boolean checkCSRF(HttpServletRequest request) {
    String cookieValue = (String) request.getAttribute(CSRF_ATTRIBUTE);

    if (Strings.isNullOrEmpty(cookieValue)) {
        logger.info("Missing CSRF cookie");
        return false;
    }

    String inputValue = request.getParameter(CSRF_INPUT_NAME);

    if (Strings.isNullOrEmpty(inputValue)) {
        logger.info("Missing CSRF input");
        return false;
    }

    boolean r = inputValue.trim().equals(cookieValue.trim());

    if (!r) {
        logger.info(String.format("Flood protection (CSRF cookie differs: cookie=%s param=%s) ip=%s url=%s",
                cookieValue, inputValue, request.getRemoteAddr(), request.getRequestURI()));
    }

    return r;
}

From source file:de.dominikschadow.javasecurity.csrf.CSRFTokenHandler.java

public static boolean isValid(HttpServletRequest request)
        throws ServletException, NoSuchAlgorithmException, NoSuchProviderException {
    if (request.getSession(false) == null) {
        throw new ServletException(MISSING_SESSION);
    }/*from   ww w .j  a v  a  2 s .c  om*/

    return StringUtils.equals(getToken(request.getSession(false)), request.getParameter(CSRF_TOKEN));
}

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

public static boolean getBooleanParameter(HttpServletRequest request, String name, boolean defaultVal) {
    String temp = request.getParameter(name);
    if ("true".equals(temp) || "on".equals(temp))
        return true;
    if ("false".equals(temp) || "off".equals(temp))
        return false;
    else//from  ww  w  .jav  a  2  s .com
        return defaultVal;
}

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

public static int getIntParameter(HttpServletRequest request, String name, int defaultNum) {
    String temp = request.getParameter(name);
    if (temp != null && !temp.equals("")) {
        int num = defaultNum;
        try {/*from   www .  jav  a 2s  .co  m*/
            num = Integer.parseInt(temp.trim());
        } catch (Exception ignored) {
        }
        return num;
    } else {
        return defaultNum;
    }
}

From source file:com.bluepandora.therap.donatelife.service.DonationService.java

public static void removeDonationRecord(HttpServletRequest request, HttpServletResponse response)
        throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();//w  w w  .  j av a  2s  .  c  o  m
    String requestName = request.getParameter("requestName");
    JSONObject jsonObject = null;

    if (request.getParameter("mobileNumber") != null && request.getParameter("donationDate") != null) {
        String mobileNumber = request.getParameter("mobileNumber");
        String donationDate = request.getParameter("donationDate");
        if (DataValidation.isValidMobileNumber(mobileNumber) && DataValidation.isValidString(donationDate)) {
            String query = GetQuery.removeDonationRecordQuery(mobileNumber, donationDate);
            boolean done = dbService.queryExcute(query);
            if (done) {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.CORRECT, Enum.MESSAGE_DONATION_REMOVED,
                        requestName);
                Debug.debugLog("MOBILE NUMBER: ", mobileNumber, " REMOVE DONATION SUCCESS");
            } else {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_ERROR, requestName);
            }
        } else {
            jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_VALUE, requestName);
        }
    } else {
        jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_LESS_PARAMETER, requestName);

    }
    SendJsonData.sendJsonData(request, response, jsonObject);
    dbService.databaseClose();
}