List of usage examples for javax.servlet.http HttpServletRequest getParameterValues
public String[] getParameterValues(String name);
String
objects containing all of the values the given request parameter has, or null
if the parameter does not exist. From source file:com.mockey.ui.ServiceSetupServlet.java
/** * /* ww w .j ava2s .c o m*/ * * @param req * basic request * @param resp * basic resp * @throws ServletException * basic * @throws IOException * basic */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] realSrvUrl = req.getParameterValues("realServiceUrl[]"); Service service = new Service(); Long serviceId = null; try { serviceId = new Long(req.getParameter("serviceId")); service = store.getServiceById(serviceId); } catch (Exception e) { // Do nothing } if (service == null) { service = new Service(); } // NEW REAL URL LIST // 1. Overwrite list of predefined URLs // 2. Ensure non-empty trim String for new Url objects. if (realSrvUrl != null) { List<Url> newUrlList = new ArrayList<Url>(); for (int i = 0; i < realSrvUrl.length; i++) { String url = realSrvUrl[i]; if (url.trim().length() > 0) { newUrlList.add(new Url(realSrvUrl[i].trim())); } } for (Url urlItem : newUrlList) { service.saveOrUpdateRealServiceUrl(urlItem); } } // UPDATE HANGTIME - optional try { service.setHangTime(Integer.parseInt(req.getParameter("hangTime"))); } catch (Exception e) { // DO NOTHING } // NAME - optional if (req.getParameter("serviceName") != null) { service.setServiceName(req.getParameter("serviceName")); } // TAG - optional if (req.getParameter("tag") != null) { service.setTag(req.getParameter("tag")); } // Last visist if (req.getParameter("lastVisit") != null) { try { String lastvisit = req.getParameter("lastVisit"); if (lastvisit.trim().length() > 0 && !"mm/dd/yyyy".equals(lastvisit.trim().toLowerCase())) { Date f = formatter.parse(lastvisit); service.setLastVisit(f.getTime()); } else { service.setLastVisit(null); } } catch (Exception e) { } } String classNameForRequestInspector = req.getParameter("requestInspectorName"); if (classNameForRequestInspector != null && classNameForRequestInspector.trim().length() > 0) { /** * OPTIONAL See if we can create an instance of a request inspector. * If yes, then set the service to the name. */ try { Class<?> clazz = Class.forName(classNameForRequestInspector); if (!clazz.isInterface() && IRequestInspector.class.isAssignableFrom(clazz)) { service.setRequestInspectorName(classNameForRequestInspector); } else { service.setRequestInspectorName(""); } } catch (ClassNotFoundException t) { logger.error("Service setup: unable to find class '" + classNameForRequestInspector + "'", t); } } // DESCRIPTION - optional if (req.getParameter("description") != null) { service.setDescription(req.getParameter("description")); } // MOCK URL - optional if (req.getParameter("url") != null) { service.setUrl(req.getParameter("url")); } Map<String, String> errorMap = ServiceValidator.validate(service); if ((errorMap != null) && (errorMap.size() == 0)) { // no errors, so create service. Util.saveSuccessMessage("Service updated.", req); Service updatedService = store.saveOrUpdateService(service); String redirectUrl = Url.getContextAwarePath("/setup?serviceId=" + updatedService.getId(), req.getContextPath()); resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); String resultingJSON = "{ \"result\": { \"redirect\": \"" + redirectUrl + "\"}}"; out.println(resultingJSON); out.flush(); out.close(); return; } else { resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); String resultingJSON = Util.getJSON(errorMap); out.println(resultingJSON); out.flush(); out.close(); } return; // AJAX thing. Return nothing at this time. }
From source file:org.openmrs.module.diseaseregistry.web.controller.workflow.WorkflowController.java
private void updateTests(HttpServletRequest request, DRWorkflow workflow) { DiseaseRegistryService drs = Context.getService(DiseaseRegistryService.class); List<DRConcept> tests = new ArrayList<DRConcept>( drs.getConceptByWorkflow(workflow, DiseaseRegistryService.NOT_INCLUDE_RETIRED)); String[] ids = request.getParameterValues("tests"); // add new and update existing tests for (int i = 0; i < ids.length; i++) { String key = ids[i];/*w w w . j a v a 2 s . c o m*/ if (StringUtils.isNumeric(key)) { String value = request.getParameter(key); DRConcept test = drs.getConcept(key); if (test == null) { // add new test test = new DRConcept(); test.setConcept(Context.getConceptService().getConcept(value)); test.setDrConceptId(key); test.setWeight(i); test.setWorkflow(workflow); test.setCreator(Context.getAuthenticatedUser()); test.setDateCreated(new Date()); drs.saveConcept(test); } else { // update concept test.setConcept(Context.getConceptService().getConcept(value)); test.setDrConceptId(key); test.setWeight(i); test.setWorkflow(workflow); test.setDateChanged(new Date()); drs.saveConcept(test); tests.remove(test); } } } // retired tests for (DRConcept test : tests) { test.setVoided(true); test.setVoidedBy(Context.getAuthenticatedUser()); test.setDateVoided(new Date()); drs.saveConcept(test); } }
From source file:com.sr.controller.PamongController.java
@RequestMapping("/kamar") public String kamar(HttpServletRequest request, ModelMap modelMap) { String[] nama = request.getParameterValues("nama[]"); String no = request.getParameter("kamar"); List<String> id = pmg.getIDByNomor(no); for (int i = 0; i < nama.length; i++) { pmg.addMahasiswa(mhs.getNimByNama(nama[i]), id.get(i)); }// www .jav a 2s . c om return "redirect:/pamong/mahasiswa#tab_kamar"; }
From source file:com.google.cloud.backend.spi.ProspectiveSearchServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { // Return if push notification is not enabled if (!backendConfigManager.isPushEnabled()) { log.info("ProspectiveSearchServlet: couldn't send push notification because it is disabled."); return;/* w w w . j a v a 2 s . com*/ } // dispatch GCM messages to each subscribers String[] subIds = req.getParameterValues("id"); // Each subId has this format "<regId>:query:<clientSubId>" for (String subId : subIds) { String regId = SubscriptionUtility.extractRegId(subId); if (isSubscriptionActive(regId)) { Entity matchedEntity = ProspectiveSearchServiceFactory.getProspectiveSearchService() .getDocument(req); if (matchedEntity != null) { log.info(String.format( "ProspectiveSearchServlet: matchedEntity.toString: " + matchedEntity.toString())); } else { log.info(String.format("ProspectiveSearchServlet: matchedEntity is null.")); } sendPushNotification(regId, subId, matchedEntity); } else { SubscriptionUtility.clearSubscriptionAndDeviceEntity(Arrays.asList(regId)); } } }
From source file:com.swiftcorp.portal.alert.web.AlertDispatchAction.java
public ActionForward removeAlert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SystemException, BusinessRuleViolationException, Exception { log.info("removeAlert() : Enter"); DynaValidatorActionForm alertForm = (DynaValidatorActionForm) form; String[] alertIdList = request.getParameterValues("deleteCheck"); String alertsRemoved = ""; for (int i = 0; alertIdList != null && i < alertIdList.length; i++) { log.info("alertId to delete::" + alertIdList[i]); String alertComponentId = alertIdList[i]; if (alertComponentId != null && !alertComponentId.equals("null") && alertComponentId.length() > 0) { AlertDTO alertDTO = (AlertDTO) alertService.get(Long.parseLong(alertComponentId)); alertService.remove(alertDTO); if (alertsRemoved != null && !alertsRemoved.equals("null") && alertsRemoved.length() > 0) { alertsRemoved += "," + alertDTO.getAlertId(); } else { alertsRemoved += alertDTO.getAlertId(); }//from w w w. java 2 s . com } System.out.println("alertId to delete::" + alertIdList[i]); } System.out.println("alertsRemoved::" + alertsRemoved); String[][] messageArgValues = { { "Alert " + alertsRemoved } }; // SearchUtil.prepareRequest ( request ); // AlertSearchUtils.prepareSearchPage ( request ); WebUtils.setSuccessMessages(request, MessageKeys.REMOVE_SUCCESS_MESSAGE_KEYS, messageArgValues); log.info("removeAlert() : Exit"); // return mapping.findForward ( ForwardNames.ALERT_SEARCH_SYSTEM_LEVEL // ); // return mapping.findForward ( ForwardNames.ALERT_HOME ); return promptAlertSearchSystemLevel(mapping, form, request, response); }
From source file:com.googlecode.vcsupdate.TeamCityController.java
private ModelAndView getModelAndView(HttpServletRequest request, HttpServletResponse response) { // Get all of the VCS roots specified in the request Set<SVcsRoot> roots = new LinkedHashSet<SVcsRoot>(); // Start by getting any root names from the request String[] names = request.getParameterValues(NAME_PARAM); if (names != null) { for (String name : names) { SVcsRoot root = vcsManager.findRootByName(name); if (root != null) roots.add(root);//from w w w.j a v a2s. co m } } // Then look for any root IDs String[] ids = request.getParameterValues(ID_PARAM); if (ids != null) { for (String id : ids) { try { SVcsRoot root = vcsManager.findRootById(Long.parseLong(id)); if (root != null) roots.add(root); } catch (NumberFormatException e) { // just move on to the next ID } } } // Finally, if the request is a POST but we've found no roots, it may be // due to bugs in some POST handling libraries. In this case, we'll // update all of the roots. if (names == null && ids == null && request.getMethod().equals("POST")) { roots.addAll(vcsManager.getAllRegisteredVcsRoots()); } // Did we get a submitted form? if (!roots.isEmpty()) { List<String> forcedVcsRootNames = new ArrayList<String>(); // Iterate through the roots for (SVcsRoot root : roots) { // Find the matching configurations List<SBuildType> builds = vcsManager.getAllConfigurationUsages(root); if (builds == null) continue; // Select the best configuration SBuildType selected = null; List<SVcsRoot> selectedRoots = null; for (SBuildType build : builds) { if (!build.isPaused() && !build.isPersonal()) { List<SVcsRoot> buildRoots = build.getVcsRoots(); if (selected == null || buildRoots.size() < selectedRoots.size()) { selected = build; selectedRoots = buildRoots; } } } // Did we find a match? if (selected == null) continue; // Kick off the modification check boolean defaultInterval = root.isUseDefaultModificationCheckInterval(); int interval = (defaultInterval ? -1 : root.getModificationCheckInterval()); root.setModificationCheckInterval(5); log("Forcing check for " + selected.getName()); selected.forceCheckingForChanges(); forcedVcsRootNames.add(root.getName()); if (defaultInterval) { root.restoreDefaultModificationCheckInterval(); } else { root.setModificationCheckInterval(interval); } } // Redirect to the done page String modelObject = forcedVcsRootNames.toString(); return new ModelAndView(doneViewName, "updatedVCSRoots", modelObject); } // Build a sample URL StringBuilder sampleUrl = new StringBuilder(); sampleUrl.append(request.getRequestURL()).append('?'); boolean appendedRoot = false; // Append the list of available roots List<SVcsRoot> list = vcsManager.getAllRegisteredVcsRoots(); if (list != null) { for (SVcsRoot root : list) { if (appendedRoot) sampleUrl.append('&'); sampleUrl.append(NAME_PARAM).append('=').append(root.getName()); appendedRoot = true; } } // If we didn't get any roots, use a sample name if (!appendedRoot) { sampleUrl.append(NAME_PARAM).append('=').append(SAMPLENAME); } // Return a simple view that explains how to use the tool String query = request.getQueryString(); if (query != null) sampleUrl.append('&').append(query); String modelObject = response.encodeURL(sampleUrl.toString()); log("Creating modelview. View: " + viewName + " and model: " + modelObject); return new ModelAndView(viewName, "sampleUrl", modelObject); }
From source file:com.jada.browser.YuiImageBrowser.java
public String performRemove(HttpServletRequest request, String currentFolder) throws Exception { String result = null;/*w ww. j a va 2 s. c o m*/ JSONEscapeObject JSONEscapeObject = new JSONEscapeObject(); String filenames[] = request.getParameterValues("filenames"); if (filenames != null) { for (int i = 0; i < filenames.length; i++) { String filename = getBaseDir(request); if (currentFolder.equals("/")) { filename += currentFolder; } filename += filenames[i]; File file = new File(filename); if (!file.exists()) { JSONEscapeObject.put("status", "failed"); JSONEscapeObject.put("message", "File " + filename + " does not exist"); return JSONEscapeObject.toHtmlString(); } removeFile(filename); } } JSONEscapeObject.put("status", "success"); result = JSONEscapeObject.toHtmlString(); return result; }
From source file:com.dianping.lion.api.http.AbstractLionServlet.java
@SuppressWarnings("unchecked") protected String getParameterString(HttpServletRequest request) { StringBuilder builder = new StringBuilder(); Enumeration<String> parameterNames = request.getParameterNames(); int i = 0;/*from w w w .jav a2 s.com*/ while (parameterNames.hasMoreElements()) { String parameterName = parameterNames.nextElement(); String[] parameterValues = request.getParameterValues(parameterName); for (String parameterValue : parameterValues) { builder.append(i++ > 0 ? "&" : StringUtils.EMPTY).append(parameterName).append("=") .append(parameterValue); } } return builder.toString(); }
From source file:com.intel.cosbench.controller.web.WorkloadConfigurationController.java
private ArrayList<Object> constructNormalStage(HttpServletRequest req) { if (req.getParameterValues("normal.checked") != null) { String workStageName = new String("normal"); ArrayList<Object> workStageList = new ArrayList<Object>(); for (int i = 0; i < req.getParameterValues("normal.checked").length; i++) { if (i > 0) { workStageName = new String("normal" + i); }//from w ww . jav a 2 s .c o m Stage stage = new Stage(workStageName); Work work = new Work(workStageName, "normal"); work.setWorkers(getParmInt(req.getParameterValues("normal.workers")[i])); work.setRampup(getParmInt(req.getParameterValues("normal.rampup")[i])); work.setRuntime(getParmInt(req.getParameterValues("normal.runtime")[i])); // read operation String rconfig = ""; Operation rOp = new Operation("read"); int rRatio = getParmInt(req.getParameterValues("read.ratio")[i], 0); rOp.setRatio(rRatio); String rcselector = req.getParameterValues("read.containers")[i]; String rcmin = req.getParameterValues("read.containers.min")[i]; String rcmax = req.getParameterValues("read.containers.max")[i]; rconfig += "containers=" + rcselector + "(" + rcmin + "," + rcmax + ");"; // "objects" section in config String roselector = req.getParameterValues("read.objects")[i]; String romin = req.getParameterValues("read.objects.min")[i]; String romax = req.getParameterValues("read.objects.max")[i]; rconfig += "objects=" + roselector + "(" + romin + "," + romax + ");"; rOp.setConfig(rconfig); work.addOperation(rOp); // write operation String wconfig = ""; Operation wOp = new Operation("write"); int wRatio = getParmInt(req.getParameterValues("write.ratio")[i], 0); wOp.setRatio(wRatio); String wcselector = req.getParameterValues("write.containers")[i]; String wcmin = req.getParameterValues("write.containers.min")[i]; String wcmax = req.getParameterValues("write.containers.max")[i]; wconfig += "containers=" + wcselector + "(" + wcmin + "," + wcmax + ");"; // "objects" section in config String woselector = req.getParameterValues("write.objects")[i]; String womin = req.getParameterValues("write.objects.min")[i]; String womax = req.getParameterValues("write.objects.max")[i]; wconfig += "objects=" + woselector + "(" + womin + "," + womax + ");"; // "sizes" section in config String wsselector = req.getParameterValues("write.sizes")[i]; String wsmin = req.getParameterValues("write.sizes.min")[i]; String wsmax = req.getParameterValues("write.sizes.max")[i]; String wsunit = req.getParameterValues("write.sizes.unit")[i]; String wsexp = ""; if ("u".equals(wsselector) || "r".equals(wsselector)) wsexp = wsselector + "(" + wsmin + "," + wsmax + ")" + wsunit; if ("c".equals(wsselector)) wsexp = wsselector + "(" + wsmin + ")" + wsunit; wconfig += "sizes=" + wsexp; wOp.setConfig(wconfig); work.addOperation(wOp); // filewrite operation String fwconfig = ""; Operation fwOp = new Operation("filewrite"); int fwRatio = getParmInt(req.getParameterValues("filewrite.ratio")[i], 0); fwOp.setRatio(fwRatio); // "containers" section in config String fwcselector = req.getParameterValues("filewrite.containers")[i]; String fwcmin = req.getParameterValues("filewrite.containers.min")[i]; String fwcmax = req.getParameterValues("filewrite.containers.max")[i]; fwconfig += "containers=" + fwcselector + "(" + fwcmin + "," + fwcmax + ");"; // "objects" section in config String fwoselector = req.getParameterValues("filewrite.fileselection")[i]; fwconfig += "fileselection=" + fwoselector + ";"; // "files" section in config String fwfselector = req.getParameterValues("filewrite.files")[i]; fwconfig += "files=" + fwfselector; fwOp.setConfig(fwconfig); work.addOperation(fwOp); // delete operation String dconfig = ""; Operation dOp = new Operation("delete"); int dRatio = getParmInt(req.getParameterValues("delete.ratio")[i], 0); dOp.setRatio(dRatio); String dcselector = req.getParameterValues("delete.containers")[i]; String dcmin = req.getParameterValues("delete.containers.min")[i]; String dcmax = req.getParameterValues("delete.containers.max")[i]; dconfig += "containers=" + dcselector + "(" + dcmin + "," + dcmax + ");"; // "objects" section in config String doselector = req.getParameterValues("delete.objects")[i]; String domin = req.getParameterValues("delete.objects.min")[i]; String domax = req.getParameterValues("delete.objects.max")[i]; dconfig += "objects=" + doselector + "(" + domin + "," + domax + ");"; dOp.setConfig(dconfig); work.addOperation(dOp); stage.addWork(work); workStageList.add(stage); } return workStageList; } return null; }
From source file:org.openmrs.module.restrictbyenctype.web.controller.EncTypeRestrictionListController.java
/** * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) *//*w w w . j a va 2 s . c om*/ @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object, BindException exceptions) throws Exception { HttpSession httpSession = request.getSession(); Integer encTypeRestId = null; try { RestrictByRoleService encTypeRestrictionService = (RestrictByRoleService) Context .getService(RestrictByRoleService.class); String[] encTypeResIds = request.getParameterValues("encTypeRes"); if (encTypeResIds != null && encTypeResIds.length > 0) { for (String eId : encTypeResIds) { encTypeRestId = Integer.parseInt(eId); EncTypeRestriction encTypeRestriction = encTypeRestrictionService .getEncTypeRestriction(encTypeRestId); if (encTypeRestriction != null) { encTypeRestrictionService.deleteEncTypeRestriction(encTypeRestriction); } else { exceptions.reject("restrictbyenctype.notfound", "Can not find encounter type Restriction with id: " + encTypeRestId); return showForm(request, response, exceptions); } } } } catch (Exception e) { exceptions.reject("restrictbyenctype.cannotdelete", "Can not delete encounter type Restriction with id: " + encTypeRestId); log.error(e); return showForm(request, response, exceptions); } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "restrictbyenctype.deleted"); return showForm(request, response, exceptions); }