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:com.log4ic.compressor.utils.HttpUtils.java

/**
 * ?bool?//from   w ww.j  a  v  a 2s. c  om
 *
 * @param request
 * @param key
 * @return
 */
public static Boolean getBooleanParam(HttpServletRequest request, String key) {
    String param = request.getParameter(key);
    boolean is = false;
    if (param != null) {
        if (StringUtils.isBlank(param)) {
            is = true;
        } else {
            try {
                is = Boolean.parseBoolean(param);
            } catch (Exception e) {
                is = true;
            }
        }
    }
    return is;
}

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

public static long getLongParameter(HttpServletRequest request, String name, long defaultNum) {
    String temp = request.getParameter(name);
    if (temp != null && !temp.equals("")) {
        long num = defaultNum;
        try {/*from   w ww .j ava2  s  .  co  m*/
            num = Long.parseLong(temp.trim());
        } catch (Exception ignored) {
        }
        return num;
    } else {
        return defaultNum;
    }
}

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

/**
 * ?????/*from  w w w .ja  v a2  s . c  o m*/
 * @param param
 * @param defaultValue
 * @return
 */
public static int getParam(HttpServletRequest req, String param, int defaultValue) {
    try {
        String value = req.getParameter(param);
        int idx = value.indexOf('#');
        if (idx != -1)
            value = value.substring(0, idx);
        return Integer.parseInt(value);
    } catch (Exception e) {
    }
    return defaultValue;
}

From source file:com.alibaba.citrus.turbine.util.CsrfToken.java

/** tokentoken<code>true</code> */
public static boolean check(HttpServletRequest request) {
    String key = getKey();/*from  w w w.  j  av  a  2 s  .c  om*/
    String fromRequest = trimToNull(request.getParameter(key));

    return fromRequest != null;
}

From source file:fr.paris.lutece.plugins.directory.web.DoDownloadFile.java

/**
 * Write in the http response the file to upload
 * @param request the http request/* ww  w. ja  v  a2  s  .  c  o  m*/
 * @param response The http response
 * @return Error Message
 *
 */
public static String doDownloadFile(HttpServletRequest request, HttpServletResponse response) {
    Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);
    String strIdFile = request.getParameter(PARAMETER_ID_FILE);
    int nIdFile = DirectoryUtils.CONSTANT_ID_NULL;

    if (StringUtils.isBlank(strIdFile) || !StringUtils.isNumeric(strIdFile)) {
        String strIdDirectoryRecord = request.getParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD);
        String strIdEntry = request.getParameter(DirectoryUtils.PARAMETER_ID_ENTRY);

        if ((StringUtils.isBlank(strIdDirectoryRecord) || !StringUtils.isNumeric(strIdDirectoryRecord))
                && (StringUtils.isBlank(strIdEntry) || !StringUtils.isNumeric(strIdEntry))) {
            return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_DURING_DOWNLOAD_FILE,
                    AdminMessage.TYPE_STOP);
        }

        int nIdDirectoryRecord = DirectoryUtils.convertStringToInt(strIdDirectoryRecord);
        int nIdEntry = DirectoryUtils.convertStringToInt(strIdEntry);
        RecordFieldFilter rfFilter = new RecordFieldFilter();
        rfFilter.setIdRecord(nIdDirectoryRecord);
        rfFilter.setIdEntry(nIdEntry);

        List<RecordField> listRecordFields = RecordFieldHome.getRecordFieldList(rfFilter, plugin);

        if ((listRecordFields != null) && !listRecordFields.isEmpty()) {
            RecordField recordField = listRecordFields.get(0);

            if ((recordField != null) && (recordField.getFile() != null)) {
                nIdFile = recordField.getFile().getIdFile();
            }
        }

        if ((nIdFile == DirectoryUtils.CONSTANT_ID_NULL) || (nIdFile == DirectoryUtils.CONSTANT_ID_ZERO)) {
            return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_DURING_DOWNLOAD_FILE,
                    AdminMessage.TYPE_STOP);
        }
    } else {
        nIdFile = DirectoryUtils.convertStringToInt(strIdFile);
    }

    File file = FileHome.findByPrimaryKey(nIdFile, plugin);
    PhysicalFile physicalFile = (file != null)
            ? PhysicalFileHome.findByPrimaryKey(file.getPhysicalFile().getIdPhysicalFile(), plugin)
            : null;

    if (physicalFile != null) {
        try {
            byte[] byteFileOutPut = physicalFile.getValue();
            DirectoryUtils.addHeaderResponse(request, response, file.getTitle());

            String strMimeType = file.getMimeType();

            if (strMimeType == null) {
                strMimeType = FileSystemUtil.getMIMEType(file.getTitle());
            }

            response.setContentType(strMimeType);
            response.setContentLength(byteFileOutPut.length);

            OutputStream os = response.getOutputStream();
            os.write(byteFileOutPut);
            os.close();
        } catch (IOException e) {
            AppLogService.error(e);
        }
    }

    return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_DURING_DOWNLOAD_FILE,
            AdminMessage.TYPE_STOP);
}

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

public static double getDoubleParameter(HttpServletRequest request, String name, double defaultNum) {
    String temp = request.getParameter(name);
    if (temp != null && !temp.equals("")) {
        double num = defaultNum;
        try {//from ww w. ja  va2  s  . com
            num = Double.parseDouble(temp.trim());
        } catch (Exception ignored) {
        }
        return num;
    } else {
        return defaultNum;
    }
}

From source file:edu.ucmerced.cas.authentication.principal.CasShibSamlService.java

public static CasShibSamlService createServiceFrom(final HttpServletRequest request,
        final HttpClient httpClient) {
    final String service = request.getParameter(CONST_PARAM_SERVICE);
    final String artifactId;
    final String requestBody = getRequestBody(request);
    final String requestId;

    if (!StringUtils.hasText(service) && !StringUtils.hasText(requestBody)) {
        return null;
    }//from w  w w.ja v a2  s  . c  om

    final String id = cleanupUrl(service);

    if (StringUtils.hasText(requestBody)) {
        final String tagStart;
        final String tagEnd;
        if (requestBody.contains(CONST_START_ARTIFACT_XML_TAG)) {
            tagStart = CONST_START_ARTIFACT_XML_TAG;
            tagEnd = CONST_END_ARTIFACT_XML_TAG;
        } else {
            tagStart = CONST_START_ARTIFACT_XML_TAG_NO_NAMESPACE;
            tagEnd = CONST_END_ARTIFACT_XML_TAG_NO_NAMESPACE;
        }
        final int startTagLocation = requestBody.indexOf(tagStart);
        final int artifactStartLocation = startTagLocation + tagStart.length();
        final int endTagLocation = requestBody.indexOf(tagEnd);

        artifactId = requestBody.substring(artifactStartLocation, endTagLocation).trim();

        // is there a request id?
        requestId = extractRequestId(requestBody);
    } else {
        artifactId = null;
        requestId = null;
    }

    // Extract the service passcode from url.
    // URLs should be in the following format:
    // /<contextPath>/shib/<appNameOrPasscode>/?
    String appNameOrPasscode = null;
    if ((request.getContextPath() != null
            ? request.getRequestURI().startsWith(request.getContextPath() + "/shib")
            : request.getRequestURI().startsWith("/shib"))) {
        String[] components = request.getRequestURI()
                .substring((request.getContextPath() != null ? request.getContextPath().length() : 0))
                .split("/");
        // 0 is the empty string before the first slash
        // 1 should be the shibX string
        // 2 should be the app name or passcode
        // 3... should be everything after the app name or passcode
        if (components.length > 3) {
            appNameOrPasscode = components[2];
            log.debug("application name or passcode = " + appNameOrPasscode);
        }
    } else {
        log.debug("no application name or passcode detected in url");
    }

    if (log.isDebugEnabled()) {
        log.debug("Attempted to extract Request from HttpServletRequest.  Results:");
        log.debug(String.format("Request Body: %s", requestBody));
        log.debug(String.format("Extracted ArtifactId: %s", artifactId));
        log.debug(String.format("Extracted Request Id: %s", requestId));
    }

    return new CasShibSamlService(id, service, artifactId, httpClient, requestId, appNameOrPasscode);
}

From source file:azkaban.server.HttpRequestUtils.java

/**
 * Retrieves the param from the http servlet request.
 *
 * @param request/*from  www .ja v a2s  . co  m*/
 * @param name
 * @param default
 *
 * @return
 */
public static String getParam(HttpServletRequest request, String name, String defaultVal) {
    String p = request.getParameter(name);
    if (p == null) {
        return defaultVal;
    }
    return p;
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java

protected static void leerUsuarioId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    UsuarioEntity e = CtrlAdmin.leerUsuarioId(Integer.parseInt(request.getParameter("1"))); // id del usuario

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONObject obj = new JSONObject();
    obj.put("id", e.getIdUsuario());
    obj.put("nombre", e.getNombres());
    obj.put("apellido", e.getApellidos());
    obj.put("tipoDocumento", e.gettDocumento());
    obj.put("documento", e.getDocumento());
    obj.put("contrasena", e.getPassword());
    obj.put("rol", "" + e.getRol());
    obj.put("email", e.getUsername());
    out.print(obj);//from w  ww  .j  ava2s  .com
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java

protected static void eliminarUsuario(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.eliminarUsuario(Integer.parseInt(request.getParameter("1"))); // id_usuario

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        if (r.get(1) == "usuario") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El usuario no existe");

        } else {/* ww  w . j  ava2s .  c  o m*/
            Util.errordeRespuesta(r, out);
        }
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}