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.bluepandora.therap.donatelife.service.GcmProfileService.java

public static void updateGCMKey(HttpServletRequest request, HttpServletResponse response) throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();/*ww  w .j  ava 2s  . c  om*/

    String requestName = request.getParameter("requsetName");
    JSONObject jsonObject = null;
    if (request.getParameter("mobileNumber") != null && request.getParameter("gcmId") != null) {
        String mobileNumber = request.getParameter("mobileNumber");
        String gcmId = request.getParameter("gcmId");

        if (gcmId == null || gcmId.equals("NULL") || gcmId.equals("null")) {
            gcmId = "";
        }

        if (DataValidation.isValidMobileNumber(mobileNumber)) {
            String query = GetQuery.updateGCMIdQuery(mobileNumber, gcmId);
            boolean done = dbService.queryExcute(query);
            if (done) {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.CORRECT, Enum.MESSAGE_GCM_ID_UPDATED);
                Debug.debugLog("Mobile Number: ", mobileNumber, " GCM UPDATION SUCCESS");
            } else {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_GCM_ID_NOT_UPDATED);
            }
        } else {
            jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_VALUE);
        }
    } 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:info.magnolia.cms.util.Resource.java

/**
 * Check for preview mode./*from w w w.  j a v  a  2s .  c  om*/
 * @param req HttpServletRequest as received in JSP or servlet
 * @return boolean , true if preview is enabled
 */
public static boolean showPreview(HttpServletRequest req) {
    // first check if its set in request scope
    if (req.getParameter(MGNL_PREVIEW_ATTRIBUTE) != null) {
        return BooleanUtils.toBoolean(req.getParameter(MGNL_PREVIEW_ATTRIBUTE));
    } else {
        HttpSession httpsession = req.getSession(false);
        if (httpsession != null) {
            return BooleanUtils.toBoolean((Boolean) httpsession.getAttribute(MGNL_PREVIEW_ATTRIBUTE));
        }
    }
    return false;
}

From source file:de.perdian.commons.servlet.ServletUtils.java

/**
 * Extracts a parameter value from the given request. The method makes
 * sure that the parameter retrieved from the request is properly cleaned
 * up, which means that any leading or trailing whitespaces will be removed
 * so the caller can expect just the plain and simple parameter value
 *
 * @param servletRequest//  w ww  .j  a v  a2 s . co m
 *     the request from which to extract the parameter value
 * @param parameterName
 *     the name of the parameter to extract
 * @param defaultValue
 *     the default value to be returned if the parameter is either not set
 *     in the given requests or evaluates to an empty String.
 */
public static String extractParameterString(HttpServletRequest servletRequest, String parameterName,
        String defaultValue) {
    String parameterValue = servletRequest.getParameter(parameterName);
    String cleanParameterValue = parameterValue == null ? null : parameterValue.trim();
    return cleanParameterValue == null || cleanParameterValue.length() <= 0 ? defaultValue
            : cleanParameterValue;
}

From source file:com.age.core.utils.web.ServletUtils.java

public static String getStringParameter(HttpServletRequest request, String name) {
    return request.getParameter(name);
}

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

public static void addFeedback(HttpServletRequest request, HttpServletResponse response) throws JSONException {

    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    dbService.databaseOpen();//from  w w w  .j  av  a  2s. c  o  m

    String requestName = request.getParameter("requestName");
    JSONObject jsonObject = null;

    if (request.getParameter("idUser") != null && request.getParameter("subject") != null
            && request.getParameter("comment") != null) {

        String idUser = request.getParameter("idUser");
        String subject = request.getParameter("subject");
        String comment = request.getParameter("comment");
        if (DataValidation.isValidString(idUser) && DataValidation.isValidString(subject)
                && DataValidation.isValidString(comment) && DataValidation.isValidLength(comment, 300)) {
            String query = GetQuery.addFeedback(idUser, subject, comment);
            boolean done = dbService.queryExcute(query);
            if (done) {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.CORRECT, Enum.MESSAGE_FEEDBACK_THANKS);
                Debug.debugLog(idUser, " FEEDBACK ADDING SUCCESS");
            } else {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_ERROR);
            }
        } else {
            jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_VALUE);
        }
    } 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:fr.paris.lutece.plugins.mydashboard.modules.nickname.web.MyDashboardNicknameApp.java

/**
 * Do change the nickname of the user/*from   w  w  w  .j a va2  s  .  c om*/
 * @param request The request
 * @return The next URL to redirect to
 */
public static String doChangeUserNickname(HttpServletRequest request) {
    LuteceUser user = SecurityService.isAuthenticationEnable()
            ? SecurityService.getInstance().getRegisteredUser(request)
            : null;

    if (user != null) {
        String strNickname = request.getParameter(PARAMETER_NICKNAME);
        UserPreferencesService.instance().setNickname(user.getName(), strNickname);
    }

    String strReferer = request.getHeader(HTML_PARAMETER_REFERER);

    if (StringUtils.isEmpty(strReferer)) {
        return MyDashboardApp.getUrlDefaultView(AppPathService.getBaseUrl(request));
    }

    return strReferer;
}

From source file:com.orig.gls.web.category.Categoryw.java

public static void handleGoCategory(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    if ((String) session.getAttribute("uname") != null) {
        session.setAttribute("catfunc", request.getParameter("function"));
        session.setAttribute("categorytype", request.getParameter("categorytype"));
        session.setAttribute("content_page", "categories/mCategories_b.jsp");
    } else {/*ww  w .  j ava  2 s .  c  o m*/
        session.setAttribute("content_page", "sessionexp.jsp");
    }
    response.sendRedirect("index.jsp");
}

From source file:com.activecq.api.utils.HttpRequestUtil.java

/**
 * Checks if the Request has non-Blank Parameter value @ key
 *
 * @param request//from  w w w .ja v a2s  .  c  o m
 * @param key
 * @return
 */
public static boolean hasParameter(HttpServletRequest request, String key) {
    if (request == null) {
        return false;
    }
    String tmp = (String) request.getParameter(key);
    return StringUtils.isNotBlank(tmp);
}

From source file:de.knowwe.core.user.UserContextUtil.java

/**
 * Returns a Map<String, String> with all parameters of a http request. This
 * is necessary because the parameter map of the http request is locked.
 * /*from  w  w w . ja v a  2  s  .c o m*/
 * @created Mar 9, 2011
 * @param request the http request
 * @return map containing the parameters of the http request.
 */
public static Map<String, String> getParameters(HttpServletRequest request) {
    Map<String, String> parameters = new HashMap<>();
    if (request != null) {
        Enumeration<?> iter = request.getParameterNames();
        boolean decode = checkForFlowChart(request.getParameter("action"));
        while (iter.hasMoreElements()) {
            String key = (String) iter.nextElement();
            String value = request.getParameter(key);
            parameters.put(key, decode ? Strings.decodeURL(value) : value);
        }
        if (request.getMethod() != null && request.getMethod().equals("POST")) {

            // do not handle file uploads, leave this to the action
            if (!ServletFileUpload.isMultipartContent(request)) {

                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));

                    String line;
                    StringBuilder bob = new StringBuilder();

                    while ((line = br.readLine()) != null) {
                        bob.append(line).append("\n");
                    }

                    parameters.put("data", bob.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return parameters;
}

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

protected static void leerUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException {
    UsuarioEntity e = CtrlAdmin.leerUsuario(request.getParameter("1")); // String nombre 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());
    out.print(obj);//from  w  w  w.  j  av  a2 s .  c  o  m
}