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

/**
 * Extrae un parmetro de tipo String del request. Si el parmetro no existe devuelve
 * el valor por defecto especificado./*from   w  w  w .j a v a2  s . c  o  m*/
 * @param request Peticin de la que extraer el parmetro.
 * @param name Nombre del parmetro
 * @param Valor per defecto del parmetro.
 * @return El valor String del parmetro o el valor por defecto si no existe.
 */
public static final String getString(HttpServletRequest request, String name, String defaultValue) {
    String value = request.getParameter(name);
    String stringValue = defaultValue;

    if (value != null) {
        try {
            return new String(value.getBytes(Config.TOMCAT_CONNECTOR_URI_ENCODING), "UTF-8").trim();
        } catch (UnsupportedEncodingException e) {
            // Ignore
        }
    }

    return stringValue;
}

From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java

/**
* Tries to destroy the current session and reclaim associated resources
*
* @param requestWrapper/*w  w w  .j  ava 2s  . c om*/
* @return true, if the session was destroyed. false, if there was none.
*/
@SuppressWarnings({ "unchecked" })
private static boolean didDestroySessionOnRequest(@NotNull HttpServletRequest requestWrapper) {
    if ("destroy".equalsIgnoreCase(requestWrapper.getParameter("m"))) {
        final HttpSession session = getSessionOrFail(requestWrapper);
        if (session != null) {
            synchronized (session) {
                final Enumeration<String> attrs = (Enumeration<String>) session.getAttributeNames();
                while (attrs.hasMoreElements())
                    session.removeAttribute(attrs.nextElement());
                session.invalidate();
            }
        }
        return true;
    } else
        return false;
}

From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.LanguageSetter.java

public static String getLanguageFromLayoutParam(HttpServletRequest req, RequestContext context)
        throws ServletException {
    logger.debug("# getLanguageFromLayoutParam ...");
    User user = context.getUser();//from  w w  w  .  j  ava  2s  .  c  o m
    String userId = context.getUserId();
    String urlLang = req.getParameter(SHARE_LANG);
    HttpSession currentSession = req.getSession();
    String sessionLang = (String) currentSession.getAttribute(SHARE_LANG);
    if (logger.isTraceEnabled()) {
        logger.trace("urlLang : " + urlLang);
        logger.trace("sessionLang : " + sessionLang);
    }

    // set language

    String language = null;
    // is no user or guest use browser language
    if (user != null && !userId.toLowerCase().equals("guest")) {
        if (urlLang != null) {
            language = urlLang;
            if (logger.isDebugEnabled()) {
                logger.debug("Use language in url :" + urlLang);
            }
        } else if (sessionLang != null && currentSession.getAttribute(userSessionok) != null) {
            // only if language already loaded from preference
            if (logger.isDebugEnabled()) {
                logger.debug("Use language stored in session :" + sessionLang);
            }
            language = sessionLang;

        } else {
            // initialize user language
            try {
                language = getUserLanguage(userId, req);
                logger.debug("Use language from user preferences :" + language);

            } catch (ConnectorServiceException e) {
                throw new ServletException(e);
            } catch (JSONException e) {
                throw new ServletException(e);
            }
            if (language == null) {
                // language not yet set so use default from browser
                language = getLanguageFromBrowser(req);
                logger.debug("Use language from browser :" + language);
            }
            currentSession.setAttribute(userSessionok, true);
        }
    } else {
        // language not yet set so use default from browser
        language = getLanguageFromBrowser(req);
        logger.debug("no user or Guest, use language from browser :" + language);
    }

    return language;

}

From source file:eu.eubrazilcc.lvl.oauth2.rest.LinkedInAuthz.java

private static String parseQuery(final HttpServletRequest request, final String param) {
    String value = null;//from  ww w .  j ava  2  s  . c o m
    if (request == null || request.getParameterValues(param) == null
            || request.getParameterValues(param).length != 1
            || isBlank(trimToNull(value = request.getParameter(param)))) {
        throw new WebApplicationException("Missing required parameters", Response.Status.BAD_REQUEST);
    }
    return value;
}

From source file:com.mobileman.projecth.web.util.UserUtils.java

public static void changePassword(User user, HttpServletRequest request, Model model, UserService service,
        ConfigurationService configurationService) {

    try {//from  w  w w  . ja v a 2 s .  c o m
        //String oldPassword = request.getParameter("oldpassword");
        String password = request.getParameter("password");
        String password2 = request.getParameter("password2");
        if (StringUtils.isNotBlank(password)) {
            if (!password.equals(password2)) {
                model.addAttribute("passwordnotsame", true);
            } else {
                service.changePassword(user.getId(), password);
                model.addAttribute("passwordchanged", true);
            }
        }
    } catch (LoginException lex) {
        switch (lex.getReason()) {
        case PASSWORD_TOO_LONG:
            model.addAttribute("errorpassword_too_long", Boolean.TRUE);
            model.addAttribute("max_password_length", configurationService.getMaxPasswordLength());
            break;
        case PASSWORD_TOO_SHORT:
            model.addAttribute("errorpassword_too_short", Boolean.TRUE);
            model.addAttribute("min_password_length", configurationService.getMinPasswordLength());
            break;
        default:
            model.addAttribute("passworderror", true);
        }
    } catch (Exception ex) {
        model.addAttribute("passworderror", true);
    }
}

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

protected static void consultarUsuariosEnTallerId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("3")),
            Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("1")));

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

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);//from  w  ww  .ja  v  a  2 s  .  co  m
    }
    out.print(list1);
}

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

protected static void consultarDocentesEnTallerId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("3")));

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

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);/*from w w  w. ja  v  a 2s  .  co m*/
    }
    out.print(list1);
}

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

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

    if (request.getParameter("mobileNumber") != null && request.getParameter("keyWord") != null
            && request.getParameter("groupId") != null && request.getParameter("hospitalId") != null) {

        String mobileNumber = request.getParameter("mobileNumber");
        String keyWord = request.getParameter("keyWord");
        String groupId = request.getParameter("groupId");
        String hospitalId = request.getParameter("hospitalId");

        if (DataValidation.isValidMobileNumber(mobileNumber) && DataValidation.isValidKeyWord(keyWord)
                && DataValidation.isValidString(groupId) && DataValidation.isValidString(hospitalId)) {

            dbService.databaseOpen();

            String hashKey = DataValidation.encryptTheKeyWord(keyWord);
            boolean validUser = CheckService.isValidUser(mobileNumber, hashKey, dbService);

            if (validUser) {

                String query = GetQuery.findBestDonatorQuery(groupId, hospitalId);
                ResultSet result = dbService.getResultSet(query);
                jsonObject = DonatorMobileNumberJson.getDonatorMobileNumberJson(result);

            } else {
                jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_USER);
            }

            dbService.databaseClose();
        } else {
            jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_VALUE);
        }
    } else {
        jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_LESS_PARAMETER);
    }

    jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, request.getParameter("requestName"));
    SendJsonData.sendJsonData(request, response, jsonObject);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void isInscritoTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    boolean b = CtrlUsuario.isInscritoTaller(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2")));
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("is", b);
    out.print(obj);/*www.j av a2  s.  c o m*/
}

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

public static void getUserDonationRecord(HttpServletRequest request, HttpServletResponse response)
        throws JSONException {
    DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD);
    JSONObject jsonObject = null;// w  w  w  .  ja v a2  s  .  co m
    if (request.getParameter("mobileNumber") != null) {
        String mobileNumber = request.getParameter("mobileNumber");

        if (DataValidation.isValidMobileNumber(mobileNumber)) {
            dbService.databaseOpen();
            String query = GetQuery.getDonationRecordQuery(mobileNumber);
            ResultSet result = dbService.getResultSet(query);
            jsonObject = DonationRecordJson.getDonationRecordJson(result);
            dbService.databaseClose();
        } else {
            jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_VALUE);
        }
    } else {
        jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_LESS_PARAMETER);

    }
    jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, request.getParameter("requestName"));
    SendJsonData.sendJsonData(request, response, jsonObject);
}