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:br.mdarte.exemplo.academico.web.geral.detalharEstudante.DetalhaEstudanteUCFormImpl.java
/** * Override to provide population of current form with request parameters when validation fails. * * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest) */// w w w . j av a 2 s. c o m public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request); if (errors != null && !errors.isEmpty()) { Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request, "DetalhaEstudanteUC"); if (formObj != null) { try { formObj.getClass() .getMethod("resetCheckBoxes", new Class[] { org.apache.struts.action.ActionMapping.class, javax.servlet.http.HttpServletRequest.class }) .invoke(formObj, new Object[] { null, null }); } catch (Exception e2) { // ignoring } final java.util.Map parameters = new java.util.HashMap(); for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) { final String name = String.valueOf(names.nextElement()); parameters.put(name, request.getParameterValues(name)); } try { org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters); } catch (java.lang.Exception populateException) { // ignore if we have an exception here (we just don't populate). } } } return errors; }
From source file:com.formkiq.core.service.workflow.WorkflowEditorServiceImpl.java
@Override public FormJSONField eventIdformulaformfieldvar(final WebFlow flow, final HttpServletRequest request) { final int formulaId = 78; FormJSONField field = new FormJSONField(); field.setId(formulaId);//from ww w . j av a 2s. c om String currentFormUUID = null; Object obj = flow.getCurrentState().getData(); if (obj instanceof FormJSON) { FormJSON currentForm = (FormJSON) obj; currentFormUUID = currentForm.getUUID(); } String formula = Arrays.first(request.getParameterValues("" + formulaId)); Pair<String, String> selectedForm = extractLabelAndValue(Arrays.first(request.getParameterValues("83"))); String selectedField = Arrays.first(request.getParameterValues("84")); String newval = selectedField; if (!selectedForm.getRight().equals(currentFormUUID)) { newval = "'" + selectedForm.getLeft() + "'" + "!" + selectedField; } if (hasText(formula)) { field.setValue(formula + newval); } else { field.setValue(newval); } return field; }
From source file:br.mdarte.exemplo.academico.web.geral.consultarEstudante.ConsultaEstudanteUCFormImpl.java
/** * Override to provide population of current form with request parameters when validation fails. * * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest) *//*from w w w .ja v a 2 s . c om*/ public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request); if (errors != null && !errors.isEmpty()) { Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request, "ConsultaEstudanteUC"); if (formObj != null) { try { formObj.getClass() .getMethod("resetCheckBoxes", new Class[] { org.apache.struts.action.ActionMapping.class, javax.servlet.http.HttpServletRequest.class }) .invoke(formObj, new Object[] { null, null }); } catch (Exception e2) { // ignoring } final java.util.Map parameters = new java.util.HashMap(); for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) { final String name = String.valueOf(names.nextElement()); parameters.put(name, request.getParameterValues(name)); } try { org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters); } catch (java.lang.Exception populateException) { // ignore if we have an exception here (we just don't populate). } } } return errors; }
From source file:org.openmrs.web.controller.report.export.DataExportListController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db/*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 obj, BindException errors) throws Exception { HttpSession httpSession = request.getSession(); String view = getFormView(); if (Context.isAuthenticated()) { String action = request.getParameter("action"); AdministrationService as = Context.getAdministrationService(); MessageSourceAccessor msa = getMessageSourceAccessor(); String success = ""; String error = ""; if ("saveProperties".equals(action)) { String dataExportBatchSize = request.getParameter("dataExportBatchSize"); GlobalProperty gp = new GlobalProperty(ReportingCompatibilityConstants.BATCH_SIZE_GP, dataExportBatchSize); as.saveGlobalProperty(gp); success = msa.getMessage("reportingcompatibility.DataExport.propertiesSaved"); } else { String[] reportList = request.getParameterValues("dataExportId"); String deleted = msa.getMessage("general.deleted"); String notDeleted = msa.getMessage("general.cannot.delete"); String textDataExport = msa.getMessage("reportingcompatibility.DataExport.dataExport"); String noneDeleted = msa.getMessage("reportingcompatibility.DataExport.nonedeleted"); String notGenerated = msa.getMessage("reportingcompatibility.DataExport.notGenerated"); String noneGenerated = msa.getMessage("reportingcompatibility.DataExport.noneGenerated"); if (msa.getMessage("reportingcompatibility.DataExport.generate").equals(action)) { if (reportList == null) error = noneGenerated; else { ReportObjectService rs = (ReportObjectService) Context .getService(ReportObjectService.class); EvaluationContext evalContext = new EvaluationContext(); evalContext.addParameterValue( new Parameter("general.user", "Authenticated User", org.openmrs.User.class, null), Context.getAuthenticatedUser()); for (String id : reportList) { DataExportReportObject report = null; try { report = (DataExportReportObject) rs.getReportObject(Integer.valueOf(id)); Long start = System.currentTimeMillis(); DataExportUtil.generateExport(report, null, evalContext); Long timeToGenerate = (System.currentTimeMillis() - start) / 1000; if (!success.equals("")) success += "<br/>"; success += msa.getMessage("reportingcompatibility.DataExport.generated", new String[] { report.getName(), timeToGenerate.toString() }); } catch (Exception e) { log.warn("Error generating report object", e); if (!error.equals("")) error += "<br/>"; if (report == null) error += textDataExport + " #" + id + " " + notGenerated; else error += textDataExport + " '" + report.getName() + "' " + notGenerated; } } } } else if (msa.getMessage("reportingcompatibility.DataExport.delete").equals(action)) { if (reportList != null) { for (String p : reportList) { // TODO convenience method deleteDataExport(Integer) ?? try { try { ReportObjectService rs = (ReportObjectService) Context .getService(ReportObjectService.class); DataExportReportObject dataExport = (DataExportReportObject) rs .getReportObject(Integer.valueOf(p)); File file = DataExportUtil.getGeneratedFile(dataExport); if (file != null && file.exists()) { file.delete(); } } catch (Exception ex) { // pass // (if this failed for any reason, we still want to delete the data export if we can) } as.deleteReportObject(Integer.valueOf(p)); if (!success.equals("")) success += "<br/>"; success += textDataExport + " " + p + " " + deleted; } catch (APIException e) { log.warn("Error deleting report object", e); if (!error.equals("")) error += "<br/>"; error += textDataExport + " " + p + " " + notDeleted; } } } else { success += noneDeleted; } } } view = getSuccessView(); if (!success.equals("")) httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success); if (!error.equals("")) httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error); } return new ModelAndView(new RedirectView(view)); }
From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java
private void debugRequest(HttpServletRequest request) { log.debug("=====================request begin=========================="); String uri = request.getRequestURI(); String queryString = request.getQueryString(); if (StringUtils.isNotBlank(queryString)) { uri = uri + "?" + queryString; }//ww w. j a v a 2 s .co m log.debug("{}:{}", request.getMethod(), uri); log.debug("remote ip:{} sessionId:{} ", IpUtils.getIpAddr(request), request.getRequestedSessionId()); log.debug("===header begin============================================"); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); String value = headersToString(request.getHeaders(name)); log.debug("{}={}", name, value); } log.debug("===header end============================================"); log.debug("===parameter begin=========================================="); Enumeration<String> parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String name = parameterNames.nextElement(); String value = StringUtils.join(request.getParameterValues(name), "||"); log.debug("{}={}", name, value); } log.debug("===parameter end=========================================="); log.debug("=====================request end=========================="); }
From source file:fr.paris.lutece.portal.web.rbac.RoleManagementJspBean.java
/** * Process the data capture form for assign users to a role * * @param request The HTTP Request// w ww. j a v a 2 s.com * @return The Jsp URL of the process result */ public String doAssignUsers(HttpServletRequest request) { String strReturn; String strActionCancel = request.getParameter(PARAMETER_CANCEL); if (strActionCancel != null) { strReturn = JSP_URL_ROLES_MANAGEMENT; } else { String strRoleKey = request.getParameter(PARAMETER_ROLE_KEY); //retrieve the selected portlets ids String[] arrayUsersIds = request.getParameterValues(PARAMETER_AVAILABLE_USER_LIST); if ((arrayUsersIds != null)) { for (int i = 0; i < arrayUsersIds.length; i++) { int nUserId = Integer.parseInt(arrayUsersIds[i]); AdminUser user = AdminUserHome.findByPrimaryKey(nUserId); if (!AdminUserHome.hasRole(user, strRoleKey)) { AdminUserHome.createRoleForUser(user.getUserId(), strRoleKey); } } } strReturn = JSP_ASSIGN_USERS_TO_ROLE + "?" + PARAMETER_ROLE_KEY + "=" + strRoleKey; } return strReturn; }
From source file:br.mdarte.exemplo.academico.web.geral.manterCurso.AlterandoCursoSalvaCursoFormImpl.java
/** * Override to provide population of current form with request parameters when validation fails. * * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest) */// w w w .j ava 2s . c o m public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request); if (errors != null && !errors.isEmpty()) { Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request, "MantemCursoUC.AlterandoCurso"); if (formObj != null) { try { formObj.getClass() .getMethod("resetCheckBoxes", new Class[] { org.apache.struts.action.ActionMapping.class, javax.servlet.http.HttpServletRequest.class }) .invoke(formObj, new Object[] { null, null }); } catch (Exception e2) { // ignoring } final java.util.Map parameters = new java.util.HashMap(); for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) { final String name = String.valueOf(names.nextElement()); parameters.put(name, request.getParameterValues(name)); } try { org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters); } catch (java.lang.Exception populateException) { // ignore if we have an exception here (we just don't populate). } } } return errors; }
From source file:br.mdarte.exemplo.academico.web.geral.manterEstudante.AlterandoEstudanteSalvaEstudanteFormImpl.java
/** * Override to provide population of current form with request parameters when validation fails. * * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest) *///from www . j a v a2s. c o m public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request); if (errors != null && !errors.isEmpty()) { Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request, "MantemEstudanteUC.AlterandoEstudante"); if (formObj != null) { try { formObj.getClass() .getMethod("resetCheckBoxes", new Class[] { org.apache.struts.action.ActionMapping.class, javax.servlet.http.HttpServletRequest.class }) .invoke(formObj, new Object[] { null, null }); } catch (Exception e2) { // ignoring } final java.util.Map parameters = new java.util.HashMap(); for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) { final String name = String.valueOf(names.nextElement()); parameters.put(name, request.getParameterValues(name)); } try { org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters); } catch (java.lang.Exception populateException) { // ignore if we have an exception here (we just don't populate). } } } return errors; }
From source file:myClass_Main.java
/** * * @param request/*from w ww. j a v a 2s . com*/ * @param response * @throws ServletException * @throws IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int option = Integer.parseInt(request.getParameter("optionValue")); String url; // do some processing here... // get response writer switch (option) { case 1: { int userValue = Integer.parseInt(request.getParameter("userValue")); String htmlres = ""; // build HTML code for (int i = 0; i < userValue; i++) { htmlres = htmlres + "<input type=\"text\" id=\"inputValue\" name=\"inputValue\" class=\"form-group form-control\" placeholder=\"Nombre de Pais " + (i + 1) + "\" required autofocus>"; } request.setAttribute("htmlres", htmlres); url = "/myPage_core.jsp"; ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); rd.forward(request, response); } break; case 2: { String[] input = request.getParameterValues("inputValue"); String sourceURL = "http://api.myjson.com/bins/vcv1"; //just a string // Connect to the URL using java's native library URL urlobject = new URL(sourceURL); HttpURLConnection conection = (HttpURLConnection) urlobject.openConnection(); conection.connect(); // Convert to a JSON object to print data String[][] contry_values = new String[10][input.length]; String zipcode = null; JSONParser jp = new JSONParser(); //from gson JSONObject root = null; JSONArray root_array = null; try { root = (JSONObject) jp.parse(new InputStreamReader(conection.getInputStream())); //Convert the input stream to a json element } catch (ParseException ex) { Logger.getLogger(myClass_Main.class.getName()).log(Level.SEVERE, null, ex); } boolean firstName = (boolean) root.containsKey("countries"); root = (JSONObject) root.get("countries"); root_array = (JSONArray) root.get("country"); //Iterator j = root_array.iterator(); for (int i = 0; i < input.length; i++) { Iterator j = root_array.iterator(); while (j.hasNext()) { JSONObject inner = (JSONObject) j.next(); if (inner.containsValue(input[i])) { contry_values[0][i] = (String) inner.get("isoNumeric"); contry_values[1][i] = (String) inner.get("countryName"); contry_values[2][i] = (String) inner.get("continentName"); contry_values[3][i] = (String) inner.get("capital"); contry_values[4][i] = (String) inner.get("languages"); if (contry_values[4][i].length() > 11) { String strOut = contry_values[4][i]; String trimedstring = strOut.substring(0, 10) + "...";// count start in 0 and 8 is excluded contry_values[4][i] = trimedstring; } contry_values[5][i] = (String) inner.get("population"); contry_values[6][i] = (String) inner.get("areaInSqKm"); contry_values[7][i] = (String) inner.get("countryCode"); contry_values[8][i] = "https://es.wikipedia.org/wiki/" + ((String) inner.get("countryName")); } } } System.out.println("The first name is: " + zipcode); request.setAttribute("firstname", zipcode); String htmlres = "<table class=\"table\">\n" + "<caption>Datos de Paises</caption>\n" + "<thead>\n" + "<tr>\n" + "<th>COD INT.</th>\n" + "<th>AVB.</th>\n" + "<th>Nombre</th>\n" + "<th>Continente</th>\n" + "<th>Capital</th>\n" + "<th>Idioma</th>\n" + "<th>Poblacion</th>\n" + "<th>Area km2</th>\n" + "<th>Wiki URL</th>\n" + "</tr>\n" + "</thead>\n" + "<tbody>"; // build HTML code for (int h = 0; h < input.length; h++) { if ((contry_values[0][h]) != null) { htmlres = htmlres + "<tr><th scope=\"row\">" + contry_values[0][h] + "</th>"; for (int g = 0; g < 9; g++) { if (g != 8) { htmlres = htmlres + "<td>" + contry_values[g][h] + "</td>"; } else { htmlres = htmlres + "<td>" + "<a href=\"" + contry_values[g][h] + "\" class=\"btn btn-info\" role=\"button\">" + contry_values[7][h] + "</a>" + "</td>"; } } htmlres = htmlres + "</tr>"; } else { htmlres = htmlres + "<tr><th scope=\"row\">" + "#Er." + h + "</th>"; htmlres = htmlres + "<td colspan=\"9\">" + "El pais \"" + input[h] + "\" no esta en la BD, verifique que el nombre esta en ingls, e intente de nuevo" + "</td>"; } } htmlres = htmlres + "<tr>"; htmlres = htmlres + "</tbody>\n" + "</table>"; request.setAttribute("htmlres", htmlres); url = "/myPage_res.jsp"; ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); rd.forward(request, response); } break; case 3: { url = "/index.jsp"; ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); rd.forward(request, response); } break; default: { url = "/index.jsp"; ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); rd.forward(request, response); } break; } }
From source file:Controller.UserController.java
@RequestMapping(value = "/Booking") public String booking(HttpServletRequest request, HttpSession session) { try {/*w ww. j ava 2 s . co m*/ String finalUrl = "redirect:/"; if (request.getParameter("language") != null) { finalUrl = "redirect:/" + "?language=" + request.getParameter("language"); } // no adults String noAdultsStr = request.getParameter("numberOfAdults"); String[] noChildsStrs = request.getParameterValues("numberOfChilds"); String packageIDStr = request.getParameter("packageID"); String tripDate = request.getParameter("selectedDate"); String tripTime = request.getParameter("selectedTime"); if (tripperService.tripperBooking(noAdultsStr, noChildsStrs, packageIDStr, tripDate, tripTime)) { finalUrl = "redirect:/Package/" + packageIDStr; } return finalUrl; } catch (Exception e) { String content = "Function: UserController - book\n" + "***Input***\n" + "numberOfAdults: " + request.getParameter("numberOfAdults") + "\n" + "numberOfChilds: " + request.getParameterValues("numberOfChilds") + "\n" + "packageIDStr: " + request.getParameter("packageID") + "\n" + "tripDate: " + request.getParameter("selectedDate") + "\n" + "selectedTime: " + request.getParameter("selectedTime") + "\n" + "**********\n" + "****Error****\n" + e.getMessage() + "\n" + "**********"; request.setAttribute("errorID", session.getId()); request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e)); return "forward:/Common/Error"; } }