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:info.magnolia.cms.taglibs.util.SimpleMailTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doEndTag() *//*www . java 2 s. c om*/ public int doEndTag() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); StringBuffer body = new StringBuffer(); // build and send email Content activePage = Resource.getActivePage(request); Iterator it; try { it = activePage.getContent(nodeCollectionName).getChildren().iterator(); } catch (RepositoryException e) { throw new NestableRuntimeException(e); } while (it.hasNext()) { Content node = (Content) it.next(); if (request.getParameterValues("field_" + node.getName()) != null) { String[] values = request.getParameterValues("field_" + node.getName()); body.append(node.getNodeData("title").getString() + "\n"); for (int i = 0; i < values.length; i++) { body.append(values[i] + "\n"); } body.append("\n"); } } String mailType = type; if (mailType == null) { mailType = MailConstants.MAIL_TEMPLATE_TEXT; } MgnlEmail email; try { email = MgnlMailFactory.getInstance().getEmailFromType(mailType); email.setToList(to); email.setCcList(cc); email.setBccList(bcc); email.setFrom(from); email.setSubject(subject); email.setBody(body.toString(), null); MgnlMailFactory.getInstance().getEmailHandler().prepareAndSendMail(email); } catch (Exception e) { // you may want to warn the user redirecting him to a different page... log.error(e.getMessage(), e); } if (StringUtils.isNotEmpty(redirect)) { HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); try { response.sendRedirect(request.getContextPath() + redirect); } catch (IOException e) { // should never happen log.error(e.getMessage(), e); } } return super.doEndTag(); }
From source file:gsn.http.rest.RestStreamHanlder.java
/** * This happens at the client/* w ww. j a v a 2s . c o m*/ */ public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException { double notificationId = Double.parseDouble(request.getParameter(PushDelivery.NOTIFICATION_ID_KEY)); PushRemoteWrapper notification = NotificationRegistry.getInstance().getNotification(notificationId); try { if (notification != null) { boolean status = true; for (String s : request.getParameterValues(PushDelivery.DATA)) { status = status && notification.manualDataInsertion(s); } if (status) response.setStatus(SUCCESS_200); else response.setStatus(_300); } else { logger.warn("Received a Http put request for an INVALID notificationId: " + notificationId); response.sendError(_300); } } catch (IOException e) { logger.warn("Failed in writing the status code into the connection.\n" + e.getMessage(), e); } }
From source file:com.aes.controller.EmpireController.java
public String getQuestionDetails(HttpServletRequest request) { List<String> questions = new ArrayList(); for (String q : request.getParameterValues("questions")) { questions.add(q);/*from w w w.ja v a2s. c o m*/ } List<String> answers = new ArrayList(); for (String a : request.getParameterValues("answers")) { answers.add(a); } List<List> choices = new ArrayList(); for (int x = 1; x < (questions.size()) + 1; x++) { List<String> ch = new ArrayList(); for (String c : request.getParameterValues("choice" + x)) { ch.add(c); } choices.add(ch); } JSONObject json = new JSONObject(); for (int x = 1; x < (questions.size()) + 1; x++) { JSONObject g = new JSONObject(); g.put("Question", questions.get(x - 1)); g.put("Answer", answers.get(x - 1)); g.put("Choices", choices.get(x - 1)); json.put(x - 1, g); } return json.toString(); }
From source file:org.openmrs.web.controller.report.export.DataExportFormController.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. jav a 2 s. co 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()) { DataExportReportObject report = (DataExportReportObject) 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)); //String startDate = ServletRequestUtils.getStringParameter(request, "startDate", ""); //String endDate = ServletRequestUtils.getStringParameter(request, "endDate", ""); //if (!startDate.equals("")) // report.setStartDate(dateFormat.parse(startDate)); //if (!endDate.equals("")) // report.setEndDate(dateFormat.parse(endDate)); // 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); String modifier = request.getParameter("conceptModifier_" + columnId); String modifierNumStr = request.getParameter("conceptModifierNum_" + columnId); Integer modifierNum = null; if (modifierNumStr.length() > 0) modifierNum = Integer.valueOf(modifierNumStr); report.addConceptColumn(columnName, modifier, modifierNum, 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); // if there are cached results for this report, delete them File cachedLastReportRun = DataExportUtil.getGeneratedFile(report); if (cachedLastReportRun != null && cachedLastReportRun.exists()) { cachedLastReportRun.delete(); } 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"); } else { view = request.getContextPath() + "/moduleServlet/reportingcompatibility/dataExportServlet?dataExportId=" + report.getReportObjectId(); } } return new ModelAndView(new RedirectView(view)); }
From source file:com.sun.faban.harness.webclient.ResultAction.java
String editArchive(HttpServletRequest request, HttpServletResponse response) throws IOException, FileNotFoundException, ParseException { String[] runIds = request.getParameterValues("select"); if (runIds == null || runIds.length < 1) { String msg;//from w w w . j a v a 2 s.c o m msg = "Select at least one runs to archive."; response.getOutputStream().println(msg); response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); return null; } EditArchiveModel model = new EditArchiveModel(); model.runIds = runIds; model.duplicates = checkArchivedRuns(runIds); if (Config.repositoryURLs != null && Config.repositoryURLs.length > 1) model.head = "Repositories"; else model.head = "Repository"; model.results = new RunResult[runIds.length]; for (int i = 0; i < runIds.length; i++) { model.results[i] = RunResult.getInstance(new RunId(runIds[i])); } // We use request attributes as not to reflect session state. request.setAttribute("editarchive.model", model); return "/edit_archive.jsp"; }
From source file:org.openmrs.web.controller.report.CohortListController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { String action = request.getParameter("method"); String error = ""; MessageSourceAccessor msa = getMessageSourceAccessor(); String title = msa.getMessage("Cohort.title"); String refByCompSearch = msa.getMessage("Cohort.referencedByACompositePatientSearch"); String couldNotDelete = msa.getMessage("Cohort.couldNotDelete"); HttpSession httpSession = request.getSession(); if ("delete".equals(action)) { String[] toDelete = request.getParameterValues("cohortId"); if (toDelete != null) { ReportObjectService rs = (ReportObjectService) Context.getService(ReportObjectService.class); List<AbstractReportObject> savedSearches = rs .getReportObjectsByType(OpenmrsConstants.REPORT_OBJECT_TYPE_PATIENTSEARCH); for (String s : toDelete) { int compositeTest = 0; for (ReportObject ro : savedSearches) { PatientSearchReportObject psro = (PatientSearchReportObject) ro; if (psro.getPatientSearch().isComposition()) { List<Object> psList = psro.getPatientSearch().getParsedComposition(); for (Object psObj : psList) { if (psObj.getClass().getName().contains("org.openmrs.reporting.PatientSearch")) { PatientSearch psInner = (PatientSearch) psObj; if (psInner.getSavedCohortId() != null) { if (psInner.getSavedCohortId() == Integer.valueOf(Integer.valueOf(s)) .intValue()) { compositeTest = 1; }//from w ww . ja v a 2s .c o m } } } } } if (compositeTest == 0) { String reason = request.getParameter("voidReason"); Cohort cohort = Context.getCohortService().getCohort(Integer.valueOf(s)); Context.getCohortService().voidCohort(cohort, reason); } else { if (!error.equals("")) { error += "<Br>"; } error += couldNotDelete + " " + title + " " + s + ", " + refByCompSearch; } if (!error.equals("")) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error); } } return new ModelAndView(new RedirectView(getSuccessView())); } } return showForm(request, response, errors); }
From source file:com.adito.security.actions.ShowAvailableAccountsDispatchAction.java
/** * @param mapping/*from w w w . j a v a 2 s. co m*/ * @param form * @param request * @param response * @return ActionForward * @throws Exception */ public ActionForward confirmAccountDeletion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_DELETE, request); String[] accounts = request.getParameterValues("username"); if (accounts == null || accounts.length != 1) { ActionMessages mesgs = new ActionMessages(); mesgs.add(Globals.ERROR_KEY, new ActionMessage("availableAccounts.singleAccountNotSelected")); saveErrors(request, mesgs); return list(mapping, form, request, response); } else { return mapping.findForward("confirmAccountDeletion"); } }
From source file:MyServlet.java
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException { ServletOutputStream out = res.getOutputStream(); res.setContentType("text/html"); out.println("<html><head><title>Basic Form Processor Output</title></head>"); out.println("<body>"); out.println("<h1>Here is your Form Data</h1>"); //extract the form data here String title = req.getParameter("title"); String name = req.getParameter("name"); String city = req.getParameter("city"); String country = req.getParameter("country"); String tel = req.getParameter("tel"); String age = req.getParameter("age"); // extracting data from the checkbox field String[] interests = req.getParameterValues("interests"); //output the data into a web page out.println("Your title is " + title); out.println("<br>Your name is " + name); out.println("<br>Your city is " + city); out.println("<br>Your country is " + country); out.println("<br>Your tel is " + tel); out.println("<br>Your interests include<ul> "); for (int i = 0; i < interests.length; i++) { out.println("<li>" + interests[i]); }/* w w w.j ava2 s. c o m*/ out.println("</ul>"); out.println("<br>Your age is " + age); out.println("</body></html>"); }
From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java
private static String getDataCartUsingSearchAPI(HttpServletRequest request) { System.out.println("---In getDataCartUsingSearchAPI---"); Document document = null;// ww w. j av a 2 s . c om String jsonContent = null; //get the ids from the servlet querystring here //these ids represent the dataset ids to be accessed in the datacart //String [] names = request.getParameterValues("id[]"); String[] names = request.getParameterValues("id"); System.out.println("id: " + names[0]); //create a new xml document with a root node named response document = new Document(new Element("response")); String peer = request.getParameter("peer"); //only do anything if there is stuff in the datacart if (names != null) { String peers[] = null; if (peer != null) { peers = peer.split(";"); } else { peers = new String[1]; peers[0] = "localhost:8983/solr"; } System.out.println("peer: " + peers[0]); for (int i = 0; i < peers.length; i++) { System.out.println("\n\nName: " + names[i] + " PEER: " + peers[i] + "\n"); } //create a new list of docElements List<LegacyDocElement> docElements = new ArrayList<LegacyDocElement>(); //iterate over the list of datasets in the id request paraemter for (int i = 0; i < names.length; i++) { peers[i] = "localhost"; String queryString = preassembleQueryStringUsingSearchAPI(request, peers[i]); queryString += "&variable=hus"; System.out.println("queryString: " + queryString); String dataset_id = names[i]; System.out.println("DatasetID: " + dataset_id); //get the json representation for each dataset JSONArray jsonArrayResponseDocs = getJSONArrayUsingSearchAPI(queryString, dataset_id); try { //create doc element LegacyDocElement docElement = new LegacyDocElement(); //add the dataset id docElement.setDatasetId(dataset_id); //file elements of the dataset (per dataset_id) List<LegacyFileElement> fileElements = new ArrayList<LegacyFileElement>(); System.out.println("Length: " + jsonArrayResponseDocs.length()); //add all other file elements for (int j = 0; j < jsonArrayResponseDocs.length(); j++) { System.out.println("\tAdding another file"); JSONObject docJSON = new JSONObject(jsonArrayResponseDocs.get(j).toString()); LegacyFileElement fileElement = createFileElementUsingSearchAPI(docJSON); fileElements.add(fileElement); } //create a count element docElement.setCount(jsonArrayResponseDocs.length()); //attach the file elements to the document docElement.setFileElements(fileElements); docElements.add(docElement); } catch (Exception e) { } } //end iterate over datasets System.out.println("DocElements size: " + docElements.size()); //create xml and convert to JSON //***UPDATE ME WITH A PROPER MARSHALLER!!!!*** String xmlStr = ""; for (int i = 0; i < docElements.size(); i++) { xmlStr += docElements.get(i).toXML(); } JSONObject returnJSON = null; try { returnJSON = XML.toJSONObject(xmlStr); } catch (JSONException e) { e.printStackTrace(); } //convert the JSON object back to a string jsonContent = returnJSON.toString(); System.out.println("JSONCONTENT\n" + jsonContent); } else { System.out.println("Names is Null"); } return jsonContent; /* System.exit(0); //only do anything if there is stuff in the datacart if(names != null) { String peers [] = null; if(peer == null) { peers = peer.split(";"); } else { peers = new String[1]; peers[0] = "localhost:8983/solr"; } for(int i=0;i<peers.length;i++) { System.out.println("\n\nName: " + names[i] + " PEER: " + peers[i] + "\n"); } //create a new list of docElements List<DocElement> docElements = new ArrayList<DocElement>(); //iterate over the list of datasets in the id request paraemter for(int i=0;i<names.length;i++) { String queryString = preassembleQueryStringUsingSearchAPI(request,peers[i]); String dataset_id = names[i]; //System.out.println("dataset_id: " + i + " " + dataset_id); //get the json representation for each dataset JSONArray jsonArrayResponseDocs = getJSONArrayUsingSearchAPI(queryString,dataset_id); try { //create doc element DocElement docElement = new DocElement(); //add the dataset id docElement.setDatasetId(dataset_id); //file elements of the dataset (per dataset_id) List<FileElement> fileElements = new ArrayList<FileElement>(); //insert initial file here //FileElement initialFileElement = createInitialFileElement1(); //add all other file elements for(int j=0;j<jsonArrayResponseDocs.length();j++) { JSONObject docJSON = new JSONObject(jsonArrayResponseDocs.get(j).toString()); FileElement fileElement = createFileElementUsingSearchAPI(docJSON); fileElements.add(fileElement); } //create a count element docElement.setCount(jsonArrayResponseDocs.length()); //attach the file elements to the document docElement.setFileElements(fileElements); docElements.add(docElement); } catch(Exception e) { System.out.println("JSON ERROR"); e.printStackTrace(); } } //create xml and convert to JSON String xmlStr = ""; for(int i=0;i<docElements.size();i++) { xmlStr += docElements.get(i).toXML(); } JSONObject returnJSON = null; try { returnJSON = XML.toJSONObject(xmlStr); } catch (JSONException e) { e.printStackTrace(); } System.out.println("xmlStr\n" + xmlStr); System.exit(0); //convert the JSON object back to a string jsonContent = returnJSON.toString(); } // if(jsonContent != null && jsonContent.length() > 1001) //System.out.println("jsonContent: " + jsonContent.subSequence(0, 1000)); return jsonContent; */ }
From source file:info.magnolia.debug.DumpHeadersFilter.java
@Override public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { long nr = count++; LoggingResponse wrappedResponse = new LoggingResponse(response); log.info("{} uri: {}", Long.toString(nr), request.getRequestURI()); log.info("{} session: {}", Long.toString(nr), Boolean.valueOf(request.getSession(false) != null)); StringBuffer params = new StringBuffer(); for (Enumeration paramEnum = request.getParameterNames(); paramEnum.hasMoreElements();) { String name = (String) paramEnum.nextElement(); params.append(name).append(" = ").append(StringUtils.join(request.getParameterValues(name), ",")); if (paramEnum.hasMoreElements()) { params.append("; "); }/*ww w. ja v a2s .co m*/ } log.info("{} parameters: {}", Long.toString(nr), params); log.info("{} method: {}", Long.toString(nr), request.getMethod()); for (Enumeration en = request.getHeaderNames(); en.hasMoreElements();) { String name = (String) en.nextElement(); log.info("{} header: {}={}", new String[] { String.valueOf(nr), name, request.getHeader(name) }); } chain.doFilter(request, wrappedResponse); log.info("{} response status: {}", Long.toString(nr), Integer.toString(wrappedResponse.getStatus())); log.info("{} response length: {}", Long.toString(nr), Long.toString(wrappedResponse.getLength())); log.info("{} response mime type: {}", Long.toString(nr), wrappedResponse.getContentType()); for (Iterator iter = wrappedResponse.getHeaders().keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); log.info(request.getRequestURI() + " response: " + name + " = " + wrappedResponse.getHeaders().get(name)); } }