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.ikon.util.WebUtils.java

/**
 * Extrae un parmetro de tipo entero del request. 
 * Si el parmetro no existe o no es valido devuelve 0.
 * @param request Peticin de la que extraer el parmetro.
 * @param name Nombre del parmetro//from   w ww. j ava2  s  .  co m
 * @return El valor int del parmetro o 0 si no existe o no es valido.
 */
public static final int getInt(HttpServletRequest request, String name) {
    String strValue = request.getParameter(name);
    int intValue = 0;

    if (strValue != null && !EMPTY_STRING.equals(strValue)) {
        try {
            intValue = Integer.parseInt(strValue);
        } catch (Throwable t) {
            // Ignore
        }
    }

    return intValue;
}

From source file:com.ikon.util.WebUtils.java

/**
 * Extrae un parmetro de tipo long del request. 
 * Si el parmetro no existe o no es valido devuelve 0.
 * @param request Peticin de la que extraer el parmetro.
 * @param name Nombre del parmetro/* w  w  w  .  j  ava2  s  .c  o  m*/
 * @return El valor int del parmetro o 0 si no existe o no es valido.
 */
public static final long getLong(HttpServletRequest request, String name) {
    String strValue = request.getParameter(name);
    long longValue = 0;

    if (strValue != null && !EMPTY_STRING.equals(strValue)) {
        try {
            longValue = Long.parseLong(strValue);
        } catch (Throwable t) {
            // Ignore
        }
    }

    return longValue;
}

From source file:com.ikon.util.WebUtils.java

/**
 * Extrae un parmetro de tipo float del request. 
 * Si el parmetro no existe o no es valido devuelve 0.
 * @param request Peticin de la que extraer el parmetro.
 * @param name Nombre del parmetro//from www  .j a v  a 2 s.  c om
 * @return El valor float del parmetro o 0 si no existe o no es valido.
 */
public static final float getFloat(HttpServletRequest request, String name) {
    String strValue = request.getParameter(name);
    float floatValue = 0;

    if (strValue != null && !EMPTY_STRING.equals(strValue)) {
        try {
            floatValue = Float.parseFloat(strValue);
        } catch (Throwable t) {
            // Ignore
        }
    }

    return floatValue;
}

From source file:ke.alphacba.cms.core.util.RequestUtils.java

/**
 * ????Map.//  w  w w .  j  a  va 2  s  .  c om
 * 
 * @param request
 * @return
 */
public static Map<String, String> getParamMap(HttpServletRequest request) {
    Map<String, String> paramMap = new HashMap<String, String>();
    Enumeration<String> enume = request.getParameterNames();
    while (enume.hasMoreElements()) {
        String paramName = enume.nextElement();
        paramMap.put(paramName, request.getParameter(paramName));
    }
    return paramMap;
}

From source file:net.duckling.ddl.util.StringUtil.java

License:asdf

/**
 * ?:*<>\"|?\/\\,json/* w w w.ja va 2s  . c  o m*/
 * @param req
 * @param resp
 * @param params
 * @return
 */
@SuppressWarnings({ "deprecation" })
public static boolean illCharCheck(HttpServletRequest req, HttpServletResponse resp, String... params) {
    if (params == null || params.length == 0) {
        return false;
    }
    for (String p : params) {
        String s = req.getParameter(p);
        if (StringUtils.isNotEmpty(s) && pattern.matcher(s).find()) {
            if (resp != null) {
                JSONObject obj = new JSONObject();
                obj.put("success", false);
                obj.put("result", false);
                obj.put("param", s);
                obj.put("message", "??<>:\"|*?/\\");
                JsonUtil.writeJSONObject(resp, obj);
            }
            return true;
        }
    }
    return false;
}

From source file:com.silverpeas.util.i18n.I18NHelper.java

public static void setI18NInfo(I18NBean bean, HttpServletRequest request) {
    String languageAndTranslationId = request.getParameter(HTMLSelectObjectName);
    String removeTranslation = request.getParameter(HTMLHiddenRemovedTranslationMode);

    setI18NInfo(bean, languageAndTranslationId, removeTranslation);
}

From source file:controllers.IndexServlet.java

private static void Track(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) {
    String userAddress = request.getParameter("userAddress");
    String fileName = request.getParameter("fileName");

    String storagePath = DocumentManager.StoragePath(fileName, userAddress);
    String body = "";

    try {//from  w  w  w . j av  a  2 s.co m
        Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
        body = scanner.hasNext() ? scanner.next() : "";
    } catch (Exception ex) {
        writer.write("get request.getInputStream error:" + ex.getMessage());
        return;
    }

    if (body.isEmpty()) {
        writer.write("empty request.getInputStream");
        return;
    }

    JSONParser parser = new JSONParser();
    JSONObject jsonObj;

    try {
        Object obj = parser.parse(body);
        jsonObj = (JSONObject) obj;
    } catch (Exception ex) {
        writer.write("JSONParser.parse error:" + ex.getMessage());
        return;
    }

    long status = (long) jsonObj.get("status");

    if (status == 2 || status == 3)//MustSave, Corrupted
    {
        String downloadUri = (String) jsonObj.get("url");

        int saved = 1;
        try {
            URL url = new URL(downloadUri);
            java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
            InputStream stream = connection.getInputStream();

            if (stream == null) {
                throw new Exception("Stream is null");
            }

            File savedFile = new File(storagePath);
            try (FileOutputStream out = new FileOutputStream(savedFile)) {
                int read;
                final byte[] bytes = new byte[1024];
                while ((read = stream.read(bytes)) != -1) {
                    out.write(bytes, 0, read);
                }

                out.flush();
            }

            connection.disconnect();

        } catch (Exception ex) {
            saved = 0;
        }
    }

    writer.write("{\"error\":0}");
}

From source file:com.github.thorqin.webapi.oauth2.OAuthServer.java

/**
 * @see OAuthClient#redirectAuthorization
 * @param request/*from   ww w  .  ja v a  2  s . c om*/
 * @return Authorization Code Request information
 */
public static AuthorizationCodeRequest getAuthorizationCodeRequest(HttpServletRequest request) {
    if (getResponseType(request).equalsIgnoreCase("code")) {
        AuthorizationCodeRequest codeRequest = new AuthorizationCodeRequest();
        codeRequest.clientId = request.getParameter("client_id");
        codeRequest.redirectUri = request.getParameter("redirect_uri");
        codeRequest.scope = request.getParameter("scope");
        codeRequest.state = request.getParameter("state");
        return codeRequest;
    } else
        return null;
}

From source file:com.bluepandora.therap.donatelife.adminpanel.AdminService.java

public static void adminLogin(HttpServletRequest request, HttpServletResponse response) throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();/*from  w  ww . ja  v a2  s. co  m*/
    String requestName = request.getParameter("requestName");
    JSONObject jsonObject = null;

    if (request.getParameter("idUser") != null && request.getParameter("accessKey") != null) {
        String idUser = request.getParameter("idUser");
        String accessKey = request.getParameter("accessKey");
        idUser = idUser.replace(" ", "");
        accessKey = accessKey.replace(" ", "");
        String hashKey = DataValidation.encryptTheKeyWord(accessKey);
        String query = AdminQuery.adminLoginQuery(idUser, hashKey);
        ResultSet result = dbService.getResultSet(query);
        jsonObject = JsonBuilder.adminProfile(result);
    } else {
        jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_LESS_PARAMETER);
    }
    jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, requestName);
    SendJsonData.sendJsonData(request, response, jsonObject);
    dbService.databaseClose();
}

From source file:com.ikon.util.WebUtils.java

/**
 * Extrae un parmetro de tipo booleano del request. 
 * Si el parmetro existe y es igual al valor especificado devuelve true, en caso
 * contrario devuelve false.//from www .j  a  va  2 s. c o  m
 * @param request Peticin de la que extraer el parmetro.
 * @param name Nombre del parmetro
 * @param trueValue Valor considerado true.
 * @return true si el parmetro existe y es igual a trueValue, false en caso contrario.
 */
public static final boolean getBoolean(HttpServletRequest request, String name, String trueValue) {
    String strValue = request.getParameter(name);
    return (strValue != null && strValue.equals(trueValue));
}