List of usage examples for javax.servlet.http HttpServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:com.google.visualization.datasource.DataSourceHelper.java
/** * Get the locale from the given request. * * @param req The http serlvet request/*from w w w . j a v a2s . co m*/ * * @return The locale for the given request. */ public static ULocale getLocaleFromRequest(HttpServletRequest req) { Locale locale; String requestLocale = req.getParameter(LOCALE_REQUEST_PARAMETER); if (requestLocale != null) { // Try to take the locale from the 'hl' parameter in the request. locale = LocaleUtil.getLocaleFromLocaleString(requestLocale); } else { // Else, take the browser locale. locale = req.getLocale(); } return ULocale.forLocale(locale); }
From source file:net.naijatek.myalumni.util.utilities.ParamUtil.java
public static String getParameter(final HttpServletRequest request, final String param, final boolean checkEmpty) throws BadInputException { String ret = request.getParameter(param); if (ret == null) { ret = ""; }/*from w w w .ja v a2s.c o m*/ ret = ret.trim(); if (checkEmpty && ret.length() == 0) { throw new BadInputException( "The parameter '" + param + "' is not allowed to be empty! Please try again."); } return ret; }
From source file:com.silverpeas.templatedesigner.servlets.TemplateDesignerRequestRouter.java
public static GenericFieldTemplate request2Field(HttpServletRequest request) throws FormException { String displayer = request.getParameter("Displayer"); String fieldName = request.getParameter("FieldName"); boolean mandatory = StringUtil.getBooleanValue(request.getParameter("Mandatory")); boolean readOnly = StringUtil.getBooleanValue(request.getParameter("ReadOnly")); boolean hidden = StringUtil.getBooleanValue(request.getParameter("Hidden")); boolean disabled = StringUtil.getBooleanValue(request.getParameter("Disabled")); boolean searchable = StringUtil.getBooleanValue(request.getParameter("Searchable")); boolean usedAsFacet = StringUtil.getBooleanValue(request.getParameter("UsedAsFacet")); String fieldType = "text"; if (displayer.equals("user")) { fieldType = "user"; } else if (displayer.equals("multipleUser")) { fieldType = "multipleUser"; } else if (displayer.equals("date")) { fieldType = "date"; } else if (displayer.equals("image") || displayer.equals("file") || displayer.equals("video")) { fieldType = "file"; } else if (displayer.equals("ldap")) { fieldType = "ldap"; } else if (displayer.equals("accessPath")) { fieldType = "accessPath"; } else if (displayer.equals("jdbc")) { fieldType = "jdbc"; } else if (displayer.equals("pdc")) { fieldType = PdcField.TYPE;/*from w w w . ja va2s . com*/ } else if (displayer.equals("group")) { fieldType = "group"; } else if (displayer.equals("sequence")) { fieldType = "sequence"; } else if (displayer.equals("explorer")) { fieldType = "explorer"; } GenericFieldTemplate field = new GenericFieldTemplate(); field.setDisplayerName(displayer); field.setFieldName(fieldName); field.setDisabled(disabled); field.setHidden(hidden); field.setMandatory(mandatory); field.setReadOnly(readOnly); field.setTypeName(fieldType); field.setSearchable(searchable); field.setUsedAsFacet(usedAsFacet); String nbMaxValues = request.getParameter("NbMaxValues"); if (StringUtil.isInteger(nbMaxValues)) { field.setMaximumNumberOfOccurrences(Integer.parseInt(nbMaxValues)); } Enumeration<String> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); if (paramName.startsWith("Param_")) { String xmlParameterName = paramName.substring(6); String xmlParameterValue = request.getParameter(paramName); if (StringUtil.isDefined(xmlParameterValue)) { Parameter parameter = new Parameter(xmlParameterName, "dummy"); parameter.getParameterValuesObj().add(new ParameterValue("fr", xmlParameterValue)); field.getParametersObj().add(parameter); } } else if (paramName.startsWith("Label_")) { String lang = paramName.substring(6); String sLabel = request.getParameter(paramName); if (StringUtil.isDefined(sLabel)) { Label label = new Label(sLabel, lang); field.getLabelsObj().add(label); } } } return field; }
From source file:de.betterform.agent.web.WebUtil.java
/** * returns an URL which is passed as request param and decodes it if necessary * * @param request the HttpServletRequest * @return an unencoded absolute Url or a relative Url * @throws java.io.UnsupportedEncodingException * in case URL is not correctly encoded * @throws java.net.MalformedURLException in case URL is not valid *//*from w w w. ja v a 2s.c o m*/ public static String getFormUrlAsString(HttpServletRequest request) throws UnsupportedEncodingException, MalformedURLException { String formPath = request.getParameter(WebFactory.FORM_PARAM_NAME); return decodeUrl(formPath, request); }
From source file:com.bluepandora.therap.donatelife.service.BloodRequestService.java
public static void addBloodRequest(HttpServletRequest request, HttpServletResponse response) throws JSONException, ParseException { DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD); dbService.databaseOpen();/*from w w w . j a v a 2 s . c om*/ deleteRequestTracker(Enum.MAX_DAY, dbService); String requestName = request.getParameter("requestName"); JSONObject jsonObject; Debug.debugLog("RequestName: ", requestName); if (request.getParameter("mobileNumber") != null && request.getParameter("groupId") != null && request.getParameter("hospitalId") != null && request.getParameter("amount") != null && request.getParameter("emergency") != null && request.getParameter("keyWord") != null && request.getParameter("reqTime") != null) { String mobileNumber = request.getParameter("mobileNumber"); String groupId = request.getParameter("groupId"); String hospitalId = request.getParameter("hospitalId"); String amount = request.getParameter("amount"); String emergency = request.getParameter("emergency"); String keyWord = request.getParameter("keyWord"); String reqTime = request.getParameter("reqTime"); String date = reqTime.substring(0, 10); if (DataValidation.isValidMobileNumber(mobileNumber) && DataValidation.isValidKeyWord(keyWord)) { String hashKey = DataValidation.encryptTheKeyWord(keyWord); boolean validUser = CheckService.isValidUser(mobileNumber, hashKey, dbService); if (validUser) { int userRequest = CheckService.requestTracker(mobileNumber, date, dbService); Debug.debugLog("USER REQUEST: ", userRequest); if (userRequest < com.bluepandora.therap.donatelife.constant.Enum.MAX_REQUEST) { boolean validGroup = CheckService.isDuplicateBloodGroup(mobileNumber, groupId, dbService); Debug.debugLog("VALID GROUP: ", validGroup); if (validGroup) { boolean validHospital = CheckService.isDuplicateHospital(mobileNumber, hospitalId, dbService); if (validHospital) { Debug.debugLog("VALID HOSPITAL: ", validHospital); String query = GetQuery.addBloodRequestQuery(reqTime, mobileNumber, groupId, amount, hospitalId, emergency); boolean done = dbService.queryExcute(query); Debug.debugLog("ADD BR: ", query); if (done) { query = GetQuery.addBloodRequestTrackerQuery(mobileNumber, reqTime); Debug.debugLog("REQUEST TRACKER ADDING: ", query); dbService.queryExcute(query); GcmService.giveGCMService(request, response, dbService); jsonObject = LogMessageJson.getLogMessageJson(Enum.CORRECT, Enum.MESSAGE_BLOOD_REQUEST_ADDED, requestName); Debug.debugLog("MOBILE NUMBER: ", mobileNumber, " ADD BLOOD REQUEST SUCCESS"); } else { jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_ERROR, requestName); } } else { jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_DUPLICATE_HOSPITAL, requestName); } } else { jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_DUPLICATE_BLOOD_GROUP, requestName); } } else { jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_CROSSED_LIMIT, requestName); } } else { jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, Enum.MESSAGE_INVALID_USER, 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(); }
From source file:edu.uci.ics.asterix.api.http.servlet.RESTAPIServlet.java
/** * Initialize the Content-Type of the response, and construct a * SessionConfig with the appropriate output writer and output-format * based on the Accept: header and other servlet parameters. *///from w ww . j av a 2 s . c om static SessionConfig initResponse(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setCharacterEncoding("utf-8"); // JSON output is the default; most generally useful for a // programmatic HTTP API OutputFormat format = OutputFormat.JSON; // First check the "output" servlet parameter. String output = request.getParameter("output"); String accept = request.getHeader("Accept"); if (output != null) { if (output.equals("CSV")) { format = OutputFormat.CSV; } else if (output.equals("ADM")) { format = OutputFormat.ADM; } } else { // Second check the Accept: HTTP header. if (accept != null) { if (accept.contains("application/x-adm")) { format = OutputFormat.ADM; } else if (accept.contains("text/csv")) { format = OutputFormat.CSV; } } } SessionConfig sessionConfig = new SessionConfig(response.getWriter(), format); // Now that format is set, output the content-type switch (format) { case ADM: response.setContentType("application/x-adm"); break; case JSON: response.setContentType("application/json"); break; case CSV: { // Check for header parameter or in Accept:. if ("present".equals(request.getParameter("header")) || (accept != null && accept.contains("header=present"))) { response.setContentType("text/csv; header=present"); sessionConfig.set(SessionConfig.FORMAT_CSV_HEADER, true); } else { response.setContentType("text/csv; header=absent"); } } } ; return sessionConfig; }
From source file:com.bluepandora.therap.donatelife.service.DataService.java
public static void getBloodRequestList(HttpServletRequest request, HttpServletResponse response) throws JSONException { DatabaseService dbService = new DatabaseService(DRIVER_NAME, DATABASE_URL, USERNAME, PASSWORD); JSONObject jsonObject = null;/*from w ww.j av a 2 s . c om*/ dbService.databaseOpen(); deleteBloodRequestBefore(Enum.MAX_DAY, dbService); if (request.getParameter("distId") != null && request.getParameter("groupId") != null) { String distId = request.getParameter("distId"); String groupId = request.getParameter("groupId"); String query = GetQuery.getBloodRequestListQuery(distId, groupId); ResultSet result = dbService.getResultSet(query); jsonObject = BloodRequestJson.getBloodRequestJson(result); } else if (request.getParameter("distId") != null) { String distId = request.getParameter("distId"); String query = GetQuery.getBloodRequestListQuery(distId); ResultSet result = dbService.getResultSet(query); jsonObject = BloodRequestJson.getBloodRequestJson(result); } else if (request.getParameter("groupId") != null) { String groupId = request.getParameter("groupId"); String query = GetQuery.getBloodRequestListByGroupIdQuery(groupId); ResultSet result = dbService.getResultSet(query); jsonObject = BloodRequestJson.getBloodRequestJson(result); } else { String query = GetQuery.getBloodRequestListQuery(); ResultSet result = dbService.getResultSet(query); jsonObject = BloodRequestJson.getBloodRequestJson(result); } jsonObject = RequestNameAdderJson.setRequestNameInJson(jsonObject, request.getParameter("requestName")); SendJsonData.sendJsonData(request, response, jsonObject); dbService.databaseClose(); }
From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.AbstractXPageApp.java
/** * Return a bean for pagination in service/dao using parameter in http * request/*from w w w . j ava 2s . c o m*/ * * @param request http request * @return paginator the populate paginator */ protected static PaginationProperties getPaginationProperties(HttpServletRequest request) { String strPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, "1"); int nCurrentPageIndex = 1; if (StringUtils.isNotEmpty(strPageIndex)) { nCurrentPageIndex = Integer.valueOf(strPageIndex); } String strNbItemPerPage = request.getParameter(PARAMETER_NB_ITEMS_PER_PAGE); String strDefaultNbItemPerPage = AppPropertiesService.getProperty(PROPERTY_RESULTS_PER_PAGE, DEFAULT_RESULTS_PER_PAGE); strNbItemPerPage = (strNbItemPerPage != null) ? strNbItemPerPage : strDefaultNbItemPerPage; int nItemsPerPage = Integer.valueOf(strNbItemPerPage); return new PaginationPropertiesImpl((nCurrentPageIndex - 1) * nItemsPerPage, nItemsPerPage); }
From source file:module.mission.presentationTier.action.SearchMissionsAction.java
private static Collection<Mission> doPagination(final HttpServletRequest request, Collection<Mission> allResults) { final CollectionPager<Mission> pager = new CollectionPager<Mission>(allResults, RESULTS_PER_PAGE); request.setAttribute("collectionPager", pager); request.setAttribute("numberOfPages", Integer.valueOf(pager.getNumberOfPages())); final String pageParameter = request.getParameter("pageNumber"); final Integer page = StringUtils.isEmpty(pageParameter) ? Integer.valueOf(1) : Integer.valueOf(pageParameter); request.setAttribute("pageNumber", page); return pager.getPage(page); }
From source file:net.shopxx.plugin.unionpayPayment.UnionpayPaymentPlugin.java
/** * ???/*w w w. j av a 2 s.c om*/ * * @param request * @return */ public static Map<String, String> getAllRequestParam(final HttpServletRequest request) { Map<String, String> res = new HashMap<String, String>(); Enumeration<?> temp = request.getParameterNames(); if (null != temp) { while (temp.hasMoreElements()) { String en = (String) temp.nextElement(); String value = request.getParameter(en); res.put(en, value); // ???<?????> if (res.get(en) == null || "".equals(res.get(en))) { // System.out.println("======??===="+en); res.remove(en); } } } return res; }