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.exilant.exility.core.HtmlRequestHandler.java
/** * extract request parameters into inData. Any repeated parameter is assumed * to be a list//w w w. j a v a 2 s . c o m * * @param req * @param data */ private void extractParametersAndFiles(HttpServletRequest req, ServiceData data) { @SuppressWarnings("unchecked") Enumeration<String> paramNames = req.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); String[] vals = req.getParameterValues(paramName); if (vals == null || vals.length == 0) { data.addValue(paramName, ""); } else if (vals.length == 1) { data.addValue(paramName, vals[0]); } else { data.addList(paramName, vals); } } this.extractFilesToDc(req, data); }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.web.PDFProducerJspBean.java
/** * Display the page to modify a configuration * @param request request//w w w. j a v a 2s .c o m * @return modify html page */ public String modifyConfigProducer(HttpServletRequest request) { String strIdDirectory = request.getParameter(PARAMETER_ID_DIRECTORY); if (!isAuthorized(strIdDirectory)) { return getErrorPage(); } String strNameConfig = request.getParameter(PARAMETER_CREATECONFIG_NAME); String strIdConfigProducer = request.getParameter(PARAMETER_ID_CONFIG_PRODUCER); String strCheckPageConfig = request.getParameter(PARAMETER_CHECK_PAGE_CONFIG); String[] listStrIdEntry = request.getParameterValues(PARAMETER_CONFIG_ENTRY); String strIdEntryFileName = request.getParameter(PARAMETER_ID_ENTRY_FILE_NAME); String strTypeConfigFileName = request.getParameter(PARAMETER_TYPE_CONFIG_FILE_NAME); String strTextFileName = request.getParameter(PARAMETER_TEXT_FILE_NAME); List<Integer> listIdEntry = new ArrayList<Integer>(); if (listStrIdEntry != null) { for (int i = 0; i < listStrIdEntry.length; i++) { if (StringUtils.isNotBlank(listStrIdEntry[i]) && StringUtils.isNumeric(listStrIdEntry[i])) { listIdEntry.add(Integer.valueOf(listStrIdEntry[i])); } } } Map<String, Object> model = new HashMap<String, Object>(); _manageConfigProducerService.loadListConfigEntry(getPlugin(), DirectoryUtils.convertStringToInt(strIdConfigProducer)); List<IEntry> listEntry = DirectoryUtils.getFormEntries(DirectoryUtils.convertStringToInt(strIdDirectory), getPlugin(), getUser()); ConfigProducer configProducer = _manageConfigProducerService.loadConfig(getPlugin(), DirectoryUtils.convertStringToInt(strIdConfigProducer)); model.put(MARK_ENTRY_LIST, listEntry); if (StringUtils.isNotBlank(strCheckPageConfig)) { model.put(MARK_ID_ENTRY_LIST, listIdEntry); } else { model.put(MARK_ID_ENTRY_LIST, _manageConfigProducerService.loadListConfigEntry(getPlugin(), DirectoryUtils.convertStringToInt(strIdConfigProducer))); } if (strTextFileName == null) { model.put(MARK_TEXT_FILE_NAME, configProducer.getTextFileName()); } else { model.put(MARK_TEXT_FILE_NAME, strTextFileName); } if (StringUtils.isBlank(strTypeConfigFileName)) { model.put(MARK_TYPE_CONFIG_FILE_NAME, configProducer.getTypeConfigFileName()); } else { model.put(MARK_TYPE_CONFIG_FILE_NAME, strTypeConfigFileName); } model.put(MARK_ID_DIRECTORY, strIdDirectory); model.put(MARK_ID_CONFIG_PRODUCER, strIdConfigProducer); model.put(MARK_CONFIG_PRODUCER, configProducer); if (StringUtils.isNotBlank(strIdEntryFileName)) { model.put(MARK_POSITION_ENTRY_FILENAME, strIdEntryFileName); } else { model.put(MARK_POSITION_ENTRY_FILENAME, String.valueOf(configProducer.getIdEntryFileName())); } model.put(MARK_LIST_ENTRIES_FILENAME, getListEntriesUrl(DirectoryUtils.convertStringToInt(strIdDirectory), request)); if (StringUtils.isNotBlank(strNameConfig)) { model.put(MARK_CREATECONFIG_NAME, strNameConfig); } HtmlTemplate templateList = AppTemplateService.getTemplate(TEMPLATE_MODIFY_CONFIG, getLocale(), model); return getAdminPage(templateList.getHtml()); }
From source file:controller.ClientController.java
@RequestMapping(value = "/ajoutercontrat", method = RequestMethod.POST) String ajoutercontratAction(HttpServletRequest request, Model model, HttpSession session, @RequestParam("file") MultipartFile file) throws ParseException, InterruptedException { //if(request.getSession()){ //int test = Integer.parseInt(request.getParameter("select")) ; //request.setAttribute("Modify", this.modif.modifcontrat(id)); //}// w w w . j av a2s.c om //session.setAttribute("Modify", this.modif.modifcontrat(id)); Set<Region> regions = new HashSet<>(); Set<Typerayon> typerayons = new HashSet<>(); java.util.Date date = new java.util.Date(); SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd"); ClientConnecte cl = new ClientConnecte((Client) session.getAttribute("UserConnected")); List<Compte> listCompte = CompteDAO.RegionCompte(); String[] choixrayon = request.getParameterValues("rayon"); String[] choixregion = request.getParameterValues("region"); for (int i = 0; i < choixrayon.length; i++) { typerayons.add(TypeRayonDAO.RayonPrec(choixrayon[i]).get(0)); System.out.println(choixrayon[i]); } for (int i = 0; i < choixregion.length; i++) { regions.add(RegionDAO.RegionPrec(choixregion[i]).get(0)); System.out.println(choixregion[i]); } String titrecontrat = request.getParameter("titre"); String freqcontrat = request.getParameter("frequence"); String durecontrat = request.getParameter("duree"); String datedebutcontrat = request.getParameter("dateDebut"); String datefincontrat = request.getParameter("dateFin"); String daterecepcontrat = request.getParameter("dateReception"); String datevalidcontrat = request.getParameter("dateValidation"); String tarifcontrat = request.getParameter("tarif"); String choixstatut = request.getParameter("statut"); Video vid = new Video(cl.getCli(), listCompte.get(0), titrecontrat, Integer.parseInt(freqcontrat), Integer.parseInt(durecontrat), sdf.parse(datedebutcontrat), sdf.parse(datefincontrat), sdf.parse(sdf.format(date)), sdf.parse(sdf.format(date)), 0, 2); vid.setRegions(regions); vid.setTyperayons(typerayons); int i = vidBDD.addcliVideo(vid); if (i != 0) { if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); // Creating the directory to store file String rootPath = System.getProperty("catalina.home"); // Create the file on server //Chemin officiel du serveur File serverFile = new File(rootPath + File.separator + "webapps" + File.separator + "manager" + File.separator + "videos" + File.separator + i + ".mp4"); System.out.println("" + serverFile); try (BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile))) { stream.write(bytes); } } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("You failed to upload "); } return "redirect:/client"; } else { return "cliEditContrat"; } }
From source file:br.mdarte.exemplo.academico.web.geral.consultarCurso.PreenchaCamposConsultaCursoFormImpl.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) */// www .j a va2 s .co 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, "ConsultaCursoUC.PreenchaCampos"); 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.maintenance.GlobalPropertyController.java
/** * The onSubmit function receives the form/command object that was modified * by the input form and saves it to the db * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) * @should save or update included properties * @should purge not included properties *///w w w. ja v a2 s. c om @SuppressWarnings("unchecked") protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { String action = request.getParameter("action"); if (action == null) { action = "cancel"; } if (action.equals(getMessageSourceAccessor().getMessage("general.save"))) { HttpSession httpSession = request.getSession(); if (Context.isAuthenticated()) { AdministrationService as = Context.getAdministrationService(); // fetch the backing object // and save it to a hashmap for easy retrieval of // already-used-GPs List<GlobalProperty> formBackingObject = (List<GlobalProperty>) obj; Map<String, GlobalProperty> formBackingObjectMap = new HashMap<String, GlobalProperty>(); for (GlobalProperty prop : formBackingObject) { formBackingObjectMap.put(prop.getProperty(), prop); } // the list we'll save to the database List<GlobalProperty> globalPropList = new ArrayList<GlobalProperty>(); String[] keys = request.getParameterValues(PROP_NAME); String[] values = request.getParameterValues(PROP_VAL_NAME); String[] descriptions = request.getParameterValues(PROP_DESC_NAME); for (int x = 0; x < keys.length; x++) { String key = keys[x]; String val = values[x]; String desc = descriptions[x]; // try to get an already-used global property for this key GlobalProperty tmpGlobalProperty = formBackingObjectMap.get(key); // if it exists, use that object...just update it if (tmpGlobalProperty != null) { tmpGlobalProperty.setPropertyValue(val); tmpGlobalProperty.setDescription(desc); globalPropList.add(tmpGlobalProperty); } else { // if it doesn't exist, create a new global property globalPropList.add(new GlobalProperty(key, val, desc)); } } try { // delete all properties not in this new list List<GlobalProperty> purgeGlobalPropList = new ArrayList<GlobalProperty>( as.getAllGlobalProperties()); purgeGlobalPropList.removeAll(globalPropList); as.purgeGlobalProperties(purgeGlobalPropList); as.saveGlobalProperties(globalPropList); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "GlobalProperty.saved"); // refresh log level from global property(ies) OpenmrsUtil.applyLogLevels(); OpenmrsUtil.setupLogAppenders(); } catch (Exception e) { log.error("Error saving properties", e); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "GlobalProperty.not.saved"); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, e.getMessage()); } return new ModelAndView(new RedirectView(getSuccessView())); } } return showForm(request, response, errors); }
From source file:com.sun.faban.harness.webclient.ResultAction.java
/** * This method is responsible for analyzing the runs. * @param request/*w ww. jav a 2s. c om*/ * @param response * @return string * @throws java.io.IOException */ public String analyze(HttpServletRequest request, HttpServletResponse response) throws IOException { EditAnalysisModel model = new EditAnalysisModel(); model.name = request.getParameter("output"); model.type = request.getParameter("type"); RunAnalyzer.Type type; if ("compare".equals(model.type)) { type = RunAnalyzer.Type.COMPARE; } else if ("average".equals(model.type)) { type = RunAnalyzer.Type.AVERAGE; } else { String msg = "Invalid analysis: " + model.name; response.getWriter().println(msg); logger.severe(msg); response.sendError(HttpServletResponse.SC_CONFLICT, msg); return null; } model.runIds = request.getParameterValues("select"); boolean analyze = false; boolean redirect = false; if (RunAnalyzer.exists(model.name)) { String replace = request.getParameter("replace"); if (replace == null) { request.setAttribute("editanalysis.model", model); return "/confirm_analysis.jsp"; } else if ("Replace".equals(replace)) { analyze = true; redirect = true; } else { redirect = true; } } else { analyze = true; redirect = true; } if (analyze) try { RunAnalyzer.clear(model.name); UserEnv usrEnv = (UserEnv) request.getSession().getAttribute("usrEnv"); new RunAnalyzer().analyze(type, model.runIds, model.name, usrEnv.getUser()); } catch (IOException e) { String msg = e.getMessage(); response.getWriter().println(msg); logger.log(Level.SEVERE, msg, e); response.sendError(HttpServletResponse.SC_CONFLICT, msg); return null; } if (redirect) //response.sendRedirect("/analysis/" + model.name + "/index.html"); response.sendRedirect("/controller/view/xan_view/analysis/" + model.name + "/" + model.type + ".xan"); return null; }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.web.PDFProducerJspBean.java
/** * Modify a configuration/* w w w. jav a 2s .com*/ * @param request request * @return a message to confirm and redirect to manage page */ public String doModifyConfigProducer(HttpServletRequest request) { String strIdDirectory = request.getParameter(PARAMETER_ID_DIRECTORY); if (!isAuthorized(strIdDirectory)) { return AdminMessageService.getMessageUrl(request, Messages.USER_ACCESS_DENIED, AdminMessage.TYPE_STOP); } String strIdConfigProducer = request.getParameter(PARAMETER_ID_CONFIG_PRODUCER); String strCheckPageConfig = request.getParameter(PARAMETER_CHECK_PAGE_CONFIG); String[] listStrIdEntry = request.getParameterValues(PARAMETER_CONFIG_ENTRY); String strIdEntryFileName = request.getParameter(PARAMETER_ID_ENTRY_FILE_NAME); String strNameConfig = request.getParameter(PARAMETER_CREATECONFIG_NAME); String strExtractNotEmpty = request.getParameter(PARAMETER_EXTRACT_NOT_EMPTY); String strTypeConfigFileName = request.getParameter(PARAMETER_TYPE_CONFIG_FILE_NAME); String strTextFileName = request.getParameter(PARAMETER_TEXT_FILE_NAME); if (StringUtils.isNotEmpty(strTextFileName)) { strTextFileName = PDFUtils.doPurgeNameFile(strTextFileName); } List<Integer> listIdEntry = new ArrayList<Integer>(); if (listStrIdEntry != null) { for (int i = 0; i < listStrIdEntry.length; i++) { if (StringUtils.isNotBlank(listStrIdEntry[i]) && StringUtils.isNumeric(listStrIdEntry[i])) { listIdEntry.add(Integer.valueOf(listStrIdEntry[i])); } } } checkEntryGroup(listIdEntry); UrlItem url = new UrlItem(JSP_MODIFY_CONFIG_PRODUCER); url.addParameter(PARAMETER_ID_DIRECTORY, strIdDirectory); url.addParameter(PARAMETER_TYPE_CONFIG_FILE_NAME, strTypeConfigFileName); url.addParameter(PARAMETER_TEXT_FILE_NAME, strTextFileName); url.addParameter(PARAMETER_EXTRACT_NOT_EMPTY, StringUtils.defaultString(strExtractNotEmpty)); if (request.getParameterMap().containsKey(PARAMETER_CREATECONFIG_SAVE)) { url.addParameter(PARAMETER_ID_CONFIG_PRODUCER, strIdConfigProducer); url.addParameter(PARAMETER_CHECK_PAGE_CONFIG, strCheckPageConfig); if (!listIdEntry.isEmpty()) { for (Integer idEntry : listIdEntry) { url.addParameter(PARAMETER_CONFIG_ENTRY, String.valueOf(idEntry)); } } if (StringUtils.isBlank(strNameConfig)) { url.addParameter(PARAMETER_ID_ENTRY_FILE_NAME, strIdEntryFileName); return AdminMessageService.getMessageUrl(request, MESSAGE_NAME_CONFIG_MISSED, url.getUrl(), AdminMessage.TYPE_ERROR); } else if (StringUtils.isBlank(strIdEntryFileName) && strIdEntryFileName.equals(DEFAULT_VALUE)) { url.addParameter(PARAMETER_CREATECONFIG_NAME, strIdEntryFileName); return AdminMessageService.getMessageUrl(request, MESSAGE_ENTRY_FILE_NAME_MISSED, url.getUrl(), AdminMessage.TYPE_ERROR); } else { url = new UrlItem(JSP_MANAGE_CONFIG_PRODUCER); url.addParameter(PARAMETER_ID_DIRECTORY, strIdDirectory); ConfigProducer configProducer = new ConfigProducer(); configProducer.setName(strNameConfig); configProducer.setIdProducerConfig(DirectoryUtils.convertStringToInt(strIdConfigProducer)); configProducer.setIdEntryFileName(DirectoryUtils.convertStringToInt(strIdEntryFileName)); configProducer.setIdDirectory(DirectoryUtils.convertStringToInt(strIdDirectory)); configProducer.setType(TYPE_CONFIG_PDF); configProducer.setTextFileName(strTextFileName); configProducer.setTypeConfigFileName(strTypeConfigFileName); if (StringUtils.isNotBlank(strExtractNotEmpty)) { configProducer.setExtractNotFilled(false); } else { configProducer.setExtractNotFilled(true); } _manageConfigProducerService.modifyProducerConfig(getPlugin(), configProducer, listIdEntry); } return AdminMessageService.getMessageUrl(request, MESSAGE_ADD_NEW_CONFIG, url.getUrl(), AdminMessage.TYPE_INFO); } else if (request.getParameterMap().containsKey(PARAMETER_CREATECONFIG_CANCEL)) { url = new UrlItem(JSP_MANAGE_CONFIG_PRODUCER); url.addParameter(PARAMETER_ID_DIRECTORY, strIdDirectory); return AdminMessageService.getMessageUrl(request, MESSAGE_CANCEL_CREATE, url.getUrl(), AdminMessage.TYPE_INFO); } else { url = new UrlItem(JSP_MODIFY_CONFIG_PRODUCER_BIS); url.addParameter(PARAMETER_CHECK_PAGE_CONFIG, strCheckPageConfig); url.addParameter(PARAMETER_ID_CONFIG_PRODUCER, strIdConfigProducer); return doCheckAll(url, strIdDirectory, listIdEntry, strNameConfig, strIdEntryFileName, strTextFileName, strTypeConfigFileName); } }
From source file:br.mdarte.exemplo.academico.web.geral.consultarEstudante.PreenchaCamposConsultaEstudanteFormImpl.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 .j a va 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.PreenchaCampos"); 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.mockey.ui.TwistInfoSetupServlet.java
/** * Handles the following activities for <code>TwistInfo</code> * //from w ww . j a v a2s. c o m */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // *********************** // 1. If type is JSON, then respond with JSON // 2. Otherwise, dispatch to JSP // 3. Create/delete/update TwistInfo // *********************** // *********************** // INITIALIZAION // *********************** Long twistInfoId = null; TwistInfo twistInfo = null; try { twistInfoId = new Long(req.getParameter(PARAMETER_KEY_TWIST_ID)); twistInfo = store.getTwistInfoById(twistInfoId); } catch (Exception e) { // Do nothing. If the value doesn't exist, // then we'll create a new TwistInfo } if (twistInfo == null) { twistInfo = new TwistInfo(); } // *********************** // DATA HANDLING // *********************** String name = req.getParameter(PARAMETER_KEY_TWIST_NAME); if (name == null || name.trim().length() == 0) { name = "TwistInfo (auto-generated)"; } String[] originationArguments = req.getParameterValues(PARAMETER_KEY_TWIST_ORIGINATION_LIST); String[] destinationArguments = req.getParameterValues(PARAMETER_KEY_TWIST_DESTINATION_LIST); // Remove any existing TwistInfo patterns. twistInfo.setPatternPairList(new ArrayList<PatternPair>()); if ((originationArguments != null && destinationArguments != null) && (originationArguments.length == destinationArguments.length)) { for (int i = 0; i < originationArguments.length; i++) { twistInfo.addPatternPair(new PatternPair(originationArguments[i], destinationArguments[i])); } } twistInfo.setName(name); twistInfo = store.saveOrUpdateTwistInfo(twistInfo); // *********************** // RESPONSE - in JSON or JSP // *********************** String responseType = req.getParameter(PARAMETER_KEY_RESPONSE_TYPE); if (PARAMETER_KEY_RESPONSE_TYPE_VALUE_JSON.equalsIgnoreCase(responseType)) { // BUILD JSON response resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); try { JSONObject jsonResponseObject = new JSONObject(); JSONObject jsonObject = new JSONObject(); jsonObject.put("success", "Twist updated"); jsonObject.put("id", "" + twistInfo.getId()); jsonObject.put("name", twistInfo.getName()); jsonResponseObject.put("result", jsonObject); out.println(jsonResponseObject.toString()); } catch (JSONException jsonException) { throw new ServletException(jsonException); } out.flush(); out.close(); return; } else { List<TwistInfo> twistInfoList = store.getTwistInfoList(); req.setAttribute("twistInfoList", twistInfoList); req.setAttribute("twistInfoIdEnabled", store.getUniversalTwistInfoId()); RequestDispatcher dispatch = req.getRequestDispatcher("/twistinfo_setup.jsp"); dispatch.forward(req, resp); return; } }