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:gov.nih.nci.cabig.caaers.web.study.SolicitedAdverseEventTab.java
@Override public void onBind(HttpServletRequest request, StudyCommand command, Errors errors) { // TODO Auto-generated method stub super.onBind(request, command, errors); if (request.getParameter("_ajaxInPlaceEditParam") != null || request.getParameter(AJAX_REQUEST_PARAMETER) != null || request.getAttribute(AJAX_REQUEST_PARAMETER) != null) return;/*from ww w. j a v a 2s . com*/ String[] epoch_ids = request.getParameterValues("epoch_id"); int indexOfEpoch = 0; for (Epoch e : command.getStudy().getActiveEpochs()) { List<SolicitedAdverseEvent> listOfSolicitedAEs = new ArrayList<SolicitedAdverseEvent>(); String[] termIDs = request.getParameterValues("epoch[" + indexOfEpoch + "]"); Term term = command.getStudy().getAeTerminology().getTerm(); if (termIDs != null) for (String termID : termIDs) { if (term.equals(Term.CTC)) { CtcTerm ctcterm = ctcTermDao.getById(Integer.parseInt(termID)); SolicitedAdverseEvent solicitedAE = new SolicitedAdverseEvent(); solicitedAE.setCtcterm(ctcterm); // Add otherMeddra term if exists if (ctcterm.isOtherRequired()) { String attributeName = "otherMeddra-" + ctcterm.getId(); String lowLevelTermIdString = (String) findInRequest(request, attributeName); if (StringUtils.isNotBlank(lowLevelTermIdString)) { LowLevelTerm lowLevelTerm = lowLevelTermDao .getById(Integer.parseInt(lowLevelTermIdString)); solicitedAE.setOtherTerm(lowLevelTerm); } attributeName = "verbatim-" + ctcterm.getId(); String verbatimString = (String) findInRequest(request, attributeName); if (StringUtils.isNotBlank(verbatimString)) solicitedAE.setVerbatim(verbatimString); } listOfSolicitedAEs.add(solicitedAE); } else { LowLevelTerm medraterm = lowLevelTermDao.getById(Integer.parseInt(termID)); SolicitedAdverseEvent solicitedAE = new SolicitedAdverseEvent(); solicitedAE.setLowLevelTerm(medraterm); listOfSolicitedAEs.add(solicitedAE); } } List<SolicitedAdverseEvent> listOfOldSolicitedAEs = e.getArms().get(0).getSolicitedAdverseEvents(); listOfOldSolicitedAEs.clear(); listOfOldSolicitedAEs.addAll(listOfSolicitedAEs); indexOfEpoch++; } retainOnlyTheseEpochsInStudy(request, command.getStudy(), epoch_ids); }
From source file:edu.vt.middleware.ldap.servlets.SearchServlet.java
/** * Handle all requests sent to this servlet. * * @param request <code>HttpServletRequest</code> * @param response <code>HttpServletResponse</code> * * @throws ServletException if an error occurs * @throws IOException if an error occurs */// w w w . ja v a2 s .c o m public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { if (this.logger.isInfoEnabled()) { this.logger.info("Performing search: " + request.getParameter("query") + " for attributes: " + request.getParameter("attrs")); } try { if (this.output == OutputType.LDIF) { response.setContentType("text/plain"); this.ldifSearch.search(request.getParameter("query"), request.getParameterValues("attrs"), new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))); } else { final String content = request.getParameter("content-type"); if (content != null && content.equalsIgnoreCase("text")) { response.setContentType("text/plain"); } else { response.setContentType("text/xml"); } final String dsmlVersion = request.getParameter("dsml-version"); if ("2".equals(dsmlVersion)) { this.dsmlv2Search.search(request.getParameter("query"), request.getParameterValues("attrs"), new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))); } else { this.dsmlv1Search.search(request.getParameter("query"), request.getParameterValues("attrs"), new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))); } } } catch (Exception e) { if (this.logger.isErrorEnabled()) { this.logger.error("Error performing search", e); } throw new ServletException(e); } }
From source file:com.mycompany.demos.Servlet2.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set response content type //response.setContentType("text/html"); // Actual logic goes here. // PrintWriter out = response.getWriter(); // out.println( "test"); String[][] info = new String[5][]; for (int i = 0; i < 5; i++) { info[i] = request.getParameterValues("data[" + i + "][]"); }/* w ww. j a va 2 s. co m*/ double[][] coordinates = new double[5][2]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { System.out.println(info[i][j]); coordinates[i][j] = Double.parseDouble(info[i][j]); } System.out.print("\n"); } VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 2).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(Location.newInstance("0")) .setType(type).setReturnToDepot(true).build(); Service[] services = new Service[5]; for (int i = 0; i < 4; i++) { services[i] = Service.Builder.newInstance(Integer.toString(i + 1)).addSizeDimension(0, 0) .setLocation(Location.newInstance(Integer.toString(i + 1))).build(); } GHRequest Grequest = null; GHResponse route = null; double[][] DistanceMatrix = new double[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { Grequest = new GHRequest(Double.parseDouble(info[i][0]), Double.parseDouble(info[i][1]), Double.parseDouble(info[j][0]), Double.parseDouble(info[j][1])); Grequest.setWeighting("fastest"); Grequest.setVehicle("car"); route = graphHopper.route(Grequest); try (PrintWriter out = new PrintWriter( "C:\\Users\\panikas\\Desktop\\diploma\\code\\Demos\\target\\Demos-1.0-SNAPSHOT\\file" + i + j + ".gpx")) { out.print(route.getBest().getInstructions().createGPX("Graphhopper", new Date().getTime(), false, false, true, false)); } catch (FileNotFoundException ex) { System.out.println("exception filenotfound"); } DistanceMatrix[i][j] = route.getBest().getDistance(); } } VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder .newInstance(false); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { //costMatrixBuilder.addTransportTime(Integer.toString(i), Integer.toString(j), dMatrixtime[i][j]); costMatrixBuilder.addTransportDistance(Integer.toString(i), Integer.toString(j), DistanceMatrix[i][j]); } } VehicleRoutingTransportCosts costMatrix = costMatrixBuilder.build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).setRoutingCost(costMatrix) .addVehicle(vehicle); for (int i = 0; i < 4; i++) { vrpBuilder.addJob(services[i]); } VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); SolutionPrinter.print(vrp, Solutions.bestOf(solutions), SolutionPrinter.Print.VERBOSE); int i; int j; int counter = 0; JSONObject point; JSONArray tspRoute = new JSONArray(); for (VehicleRoute jroute : Solutions.bestOf(solutions).getRoutes()) { TourActivity prevAct = jroute.getStart(); // System.out.println(prevAct.getLocation().getId()); for (TourActivity act : jroute.getActivities()) { i = Integer.parseInt(prevAct.getLocation().getId()); j = Integer.parseInt(act.getLocation().getId()); point = new JSONObject(); point.put("id", i); //System.out.println(prevAct.getLocation()); // System.out.println(Integer.parseInt(act.getLocation().getId())); Grequest = new GHRequest(coordinates[i][0], coordinates[i][1], coordinates[j][0], coordinates[j][1]); Grequest.setWeighting("fastest"); Grequest.setVehicle("car"); route = graphHopper.route(Grequest); System.out.println(counter); try (PrintWriter out = new PrintWriter( "C:\\Users\\panikas\\Desktop\\diploma\\code\\Demos\\target\\Demos-1.0-SNAPSHOT\\file" + counter + ".gpx")) { out.print(route.getBest().getInstructions().createGPX("Graphhopper", new Date().getTime(), false, false, true, false)); } catch (FileNotFoundException ex) { System.out.println("exception filenotfound"); } prevAct = act; counter++; tspRoute.add(point); } // System.out.println(jroute.getEnd().getLocation().getId()); i = Integer.parseInt(prevAct.getLocation().getId()); j = Integer.parseInt(jroute.getEnd().getLocation().getId()); point = new JSONObject(); point.put("id", i); tspRoute.add(point); Grequest = new GHRequest(coordinates[i][0], coordinates[i][1], coordinates[j][0], coordinates[j][1]); Grequest.setWeighting("fastest"); Grequest.setVehicle("car"); route = graphHopper.route(Grequest); System.out.println(counter); try (PrintWriter out = new PrintWriter( "C:\\Users\\panikas\\Desktop\\diploma\\code\\Demos\\target\\Demos-1.0-SNAPSHOT\\file" + counter + ".gpx")) { out.print(route.getBest().getInstructions().createGPX("Graphhopper", new Date().getTime(), false, false, true, false)); } catch (FileNotFoundException ex) { System.out.println("exception filenotfound"); } counter++; } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(tspRoute.toString()); System.out.println("done"); }
From source file:com.aes.controller.EmpireController.java
public int getQuestionNumber(HttpServletRequest request) { List<String> questions = new ArrayList(); for (String q : request.getParameterValues("questions")) { questions.add(q);/*from www.j a v a2 s . c o m*/ } return questions.size(); }
From source file:org.snaker.framework.form.web.FormDataController.java
private FormData buildFormData(Form form, HttpServletRequest request) { FormData formData = new FormData(form); formData.setProcessId(request.getParameter("processId")); formData.setOrderId(request.getParameter("orderId")); formData.setTaskId(request.getParameter("taskId")); List<DbTable> tables = form.getTables(); if (tables != null && tables.size() > 0) { for (DbTable table : tables) { if (table.isSub()) { Map<String, String[]> value = new HashMap<String, String[]>(); for (Field field : table.getFields()) { value.put(field.getName(), request.getParameterValues(table.getName() + "_" + field.getName())); }// w ww .j a v a2 s. c om formData.addSubData(table, value); } else { Map<String, String> value = new HashMap<String, String>(); for (Field field : table.getFields()) { value.put(field.getName(), request.getParameter(table.getName() + "_" + field.getName())); } formData.addFieldData(table, value); } } } return formData; }
From source file:org.openmrs.web.controller.report.export.RowPerObsDataExportFormController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db/*from ww w.j a va2 s . c o m*/ * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { RowPerObsDataExportReportObject report = (RowPerObsDataExportReportObject) obj; // create PatientSet from selected values in report String[] patientIds = request.getParameterValues("patientId"); report.setPatientIds(new Vector<Integer>()); if (patientIds != null) for (String patientId : patientIds) if (patientId != null && !patientId.equals("")) report.addPatientId(Integer.valueOf(patientId)); Integer location = ServletRequestUtils.getIntParameter(request, "location", 0); if (location > 0) report.setLocation(Context.getLocationService().getLocation(location)); // define columns for report object String[] columnIds = request.getParameterValues("columnId"); report.setColumns(new Vector<ExportColumn>()); if (columnIds != null) { for (String columnId : columnIds) { String columnName = request.getParameter("simpleName_" + columnId); if (columnName != null) // simple column report.addSimpleColumn(columnName, request.getParameter("simpleValue_" + columnId)); else { columnName = request.getParameter("conceptColumnName_" + columnId); if (columnName != null) { // concept column String conceptId = request.getParameter("conceptId_" + columnId); try { Integer.valueOf(conceptId); } catch (NumberFormatException e) { // for backwards compatibility to pre 1.0.43 Concept c = Context.getConceptService().getConceptByName(conceptId); if (c == null) throw new APIException("Concept name: '" + conceptId + "' could not be found in the dictionary"); conceptId = c.getConceptId().toString(); } String[] extras = request.getParameterValues("conceptExtra_" + columnId); report.setRowPerObsColumn(columnName, conceptId, extras); } else { columnName = request.getParameter("calculatedName_" + columnId); if (columnName != null) { // calculated column String columnValue = request.getParameter("calculatedValue_" + columnId); report.addCalculatedColumn(columnName, columnValue); } else { columnName = request.getParameter("cohortName_" + columnId); if (columnName != null) { // cohort column String cohortIdValue = request.getParameter("cohortIdValue_" + columnId); String filterIdValue = request.getParameter("filterIdValue_" + columnId); String searchIdValue = request.getParameter("patientSearchIdValue_" + columnId); String valueIfTrue = request.getParameter("cohortIfTrue_" + columnId); String valueIfFalse = request.getParameter("cohortIfFalse_" + columnId); Integer cohortId = null; Integer filterId = null; Integer searchId = null; try { cohortId = Integer.valueOf(cohortIdValue); } catch (Exception ex) { } try { filterId = Integer.valueOf(filterIdValue); } catch (Exception ex) { } try { searchId = Integer.valueOf(searchIdValue); } catch (Exception ex) { } if (cohortId != null || filterId != null || searchId != null) report.addCohortColumn(columnName, cohortId, filterId, searchId, valueIfTrue, valueIfFalse); } else log.warn("Cannot determine column type for column: " + columnId); } } } } } String saveAsNew = ServletRequestUtils.getStringParameter(request, "saveAsNew", ""); if (!saveAsNew.equals("")) report.setReportObjectId(null); ReportObjectService rs = (ReportObjectService) Context.getService(ReportObjectService.class); rs.saveReportObject(report); String action = ServletRequestUtils.getRequiredStringParameter(request, "action"); MessageSourceAccessor msa = getMessageSourceAccessor(); if (action.equals(msa.getMessage("reportingcompatibility.DataExport.save"))) { view = getSuccessView(); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "reportingcompatibility.DataExport.saved"); } } return new ModelAndView(new RedirectView(view)); }
From source file:com.openkm.servlet.frontend.DownloadServlet.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("service({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String path = request.getParameter("path"); String uuid = request.getParameter("uuid"); String[] uuidList = request.getParameterValues("uuidList"); String[] pathList = request.getParameterValues("pathList"); String checkout = request.getParameter("checkout"); String ver = request.getParameter("ver"); boolean export = request.getParameter("export") != null; boolean inline = request.getParameter("inline") != null; File tmp = File.createTempFile("okm", ".tmp"); InputStream is = null;/*from w w w.j a va 2 s.c o m*/ updateSessionManager(request); try { // Now an document can be located by UUID if (uuid != null && !uuid.equals("")) { uuid = FormatUtil.sanitizeInput(uuid); path = OKMRepository.getInstance().getNodePath(null, uuid); } else if (path != null) { path = FormatUtil.sanitizeInput(path); path = new String(path.getBytes("ISO-8859-1"), "UTF-8"); } if (export) { if (exportZip) { FileOutputStream os = new FileOutputStream(tmp); String fileName = "export.zip"; if (path != null) { exportFolderAsZip(path, os); fileName = PathUtils.getName(path) + ".zip"; } else if (uuidList != null || pathList != null) { // Export into a zip file multiple documents List<String> paths = new ArrayList<String>(); if (uuidList != null) { for (String uuidElto : uuidList) { String foo = new String(uuidElto.getBytes("ISO-8859-1"), "UTF-8"); paths.add(OKMRepository.getInstance().getNodePath(null, foo)); } } else if (pathList != null) { for (String pathElto : pathList) { String foo = new String(pathElto.getBytes("ISO-8859-1"), "UTF-8"); paths.add(foo); } } fileName = PathUtils.getName(PathUtils.getParent(paths.get(0))); exportDocumentsAsZip(paths, os, fileName); fileName += ".zip"; } os.flush(); os.close(); is = new FileInputStream(tmp); // Send document WebUtils.sendFile(request, response, fileName, MimeTypeConfig.MIME_ZIP, inline, is); } else if (exportJar) { // Get document FileOutputStream os = new FileOutputStream(tmp); exportFolderAsJar(path, os); os.flush(); os.close(); is = new FileInputStream(tmp); // Send document String fileName = PathUtils.getName(path) + ".jar"; WebUtils.sendFile(request, response, fileName, "application/x-java-archive", inline, is); } } else { if (OKMDocument.getInstance().isValid(null, path)) { // Get document Document doc = OKMDocument.getInstance().getProperties(null, path); if (ver != null && !ver.equals("")) { is = OKMDocument.getInstance().getContentByVersion(null, path, ver); } else { is = OKMDocument.getInstance().getContent(null, path, checkout != null); } // Send document String fileName = PathUtils.getName(doc.getPath()); WebUtils.sendFile(request, response, fileName, doc.getMimeType(), inline, is); } else if (OKMMail.getInstance().isValid(null, path)) { // Get mail Mail mail = OKMMail.getInstance().getProperties(null, path); // Send mail ServletOutputStream sos = response.getOutputStream(); String fileName = PathUtils.getName(mail.getSubject() + ".eml"); WebUtils.prepareSendFile(request, response, fileName, MimeTypeConfig.MIME_EML, inline); response.setContentLength((int) mail.getSize()); MimeMessage m = MailUtils.create(null, mail); m.writeTo(sos); sos.flush(); sos.close(); } } } catch (PathNotFoundException e) { log.warn(e.getMessage(), e); throw new ServletException(new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMDownloadService, ErrorCode.CAUSE_PathNotFound), e.getMessage())); } catch (RepositoryException e) { log.warn(e.getMessage(), e); throw new ServletException( new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMDownloadService, ErrorCode.CAUSE_Repository), e.getMessage())); } catch (IOException e) { log.error(e.getMessage(), e); throw new ServletException(new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMDownloadService, ErrorCode.CAUSE_IO), e.getMessage())); } catch (DatabaseException e) { log.error(e.getMessage(), e); throw new ServletException(new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMDownloadService, ErrorCode.CAUSE_Database), e.getMessage())); } catch (Exception e) { log.error(e.getMessage(), e); throw new ServletException(new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMDownloadService, ErrorCode.CAUSE_General), e.getMessage())); } finally { IOUtils.closeQuietly(is); FileUtils.deleteQuietly(tmp); } log.debug("service: void"); }
From source file:org.openmrs.scheduler.web.controller.SchedulerListController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db/*from w w w . j a v a2 s . c om*/ * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); // //Locale locale = request.getLocale(); String view = getFormView(); StringBuffer success = new StringBuffer(); StringBuffer error = new StringBuffer(); String action = request.getParameter("action"); MessageSourceAccessor msa = getMessageSourceAccessor(); String[] taskList = request.getParameterValues("taskId"); SchedulerService schedulerService = Context.getSchedulerService(); if (taskList != null) { for (String taskId : taskList) { // Argument to pass to the success/error message Object[] args = new Object[] { taskId }; try { TaskDefinition task = schedulerService.getTask(Integer.valueOf(taskId)); // If we can get the name, let's use it if (task != null) { args = new Object[] { task.getName() }; } if (action.equals(msa.getMessage("Scheduler.taskList.delete"))) { if (!task.getStarted()) { schedulerService.deleteTask(Integer.valueOf(taskId)); success.append(msa.getMessage("Scheduler.taskList.deleted", args)); } else { error.append(msa.getMessage("Scheduler.taskList.deleteNotAllowed", args)); } } else if (action.equals(msa.getMessage("Scheduler.taskList.stop"))) { schedulerService.shutdownTask(task); success.append(msa.getMessage("Scheduler.taskList.stopped", args)); } else if (action.equals(msa.getMessage("Scheduler.taskList.start"))) { schedulerService.scheduleTask(task); success.append(msa.getMessage("Scheduler.taskList.started", args)); } } catch (APIException e) { log.warn("Error processing schedulerlistcontroller task", e); error.append(msa.getMessage("Scheduler.taskList.error", args)); } catch (SchedulerException ex) { log.error("Error processing schedulerlistcontroller task", ex); error.append(msa.getMessage("Scheduler.taskList.error", args)); } } } else { error.append(msa.getMessage("Scheduler.taskList.requireTask")); } view = getSuccessView(); if (!"".equals(success.toString())) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success.toString()); } if (!"".equals(error.toString())) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error.toString()); } return new ModelAndView(new RedirectView(view)); }