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:org.openmrs.web.controller.patient.PatientListController.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()) { String[] patientList = request.getParameterValues("patientId"); PatientService ps = Context.getPatientService(); for (String o : patientList) { //TODO convenience method deletePatient(Integer, String) ?? ps.voidPatient(ps.getPatient(Integer.valueOf(o)), ""); } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Patient.voided"); view = getSuccessView(); } return new ModelAndView(new RedirectView(view)); }
From source file:org.openmrs.module.adminui.page.controller.location.LocationPageController.java
/** * //from ww w. java 2 s. c o m * @param model * @param location * @param errors * @param locationService * @param locationValidator * @param messageSource * @param messageSourceService * @param request * @return */ @RequestMapping(value = "/save", method = RequestMethod.POST) public String post(PageModel model, @ModelAttribute("location") @BindParams Location location, BindingResult errors, @SpringBean("locationService") LocationService locationService, @SpringBean("locationValidator") LocationValidator locationValidator, @SpringBean("messageSource") MessageSource messageSource, @RequestParam(required = false, value = "save") String saveFlag, @RequestParam(required = false, value = "retire") String retireFlag, HttpServletRequest request) { Errors newErrors = new BindException(location, "location"); locationValidator.validate(location, newErrors); String[] locationTags = request.getParameterValues("locTags"); Set<LocationTag> tags = new HashSet<LocationTag>(); if (locationTags != null && locationTags.length > 0) { for (String x : locationTags) { LocationTag tag = locationService.getLocationTagByName(x); tags.add(tag); } location.setTags(tags); } LocationAttribute attr = new LocationAttribute(); List<LocationAttributeType> locationAttributeList = locationService.getAllLocationAttributeTypes(); for (LocationAttributeType locAttr : locationAttributeList) { attr.setLocationAttributeId(locAttr.getId()); attr.setValue(request.getParameter("attribute." + locAttr.getId())); attr.setLocation(location); } if (!newErrors.hasErrors()) { try { if (saveFlag.length() > 3) { locationService.saveLocation(location); request.getSession().setAttribute(AdminUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, "adminui.location.saved"); } else if (retireFlag.length() > 3) { String reason = request.getParameter("retireReason"); locationService.retireLocation(location, reason); request.getSession().setAttribute(AdminUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, "adminui.location.retired"); } return "redirect:/adminui/location/manageLocations.page"; } catch (Exception e) { log.warn("Some error occurred while saving location details:", e); request.getSession().setAttribute(AdminUiConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, "adminui.save.fail"); } } else { sendErrorMessage(errors, messageSource, request); } model.addAttribute("errors", newErrors); model.addAttribute("location", location); return "location/location"; }
From source file:com.mockey.ui.InjectRealUrlPerServiceServlet.java
/** * Injects real URLs per service. For example, if real url is * /*from w ww . jav a2s . co m*/ * <pre> * http://qa1.google.com/search * </pre> * * and match is * * <pre> * http://qa3.google.com/ * </pre> * * then this method builds URL as * * <pre> * http://qa3.google.com/search * </pre> * * * @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 matchPattern = req.getParameter("match"); String[] replacementArray = req.getParameterValues("replacement[]"); JSONObject successOrFail = new JSONObject(); if (matchPattern != null && replacementArray != null) { for (Long serviceId : store.getServiceIds()) { Service service = store.getServiceById(serviceId); List<Url> newUrlList = new ArrayList<Url>(); // Build a list of real Url objects. for (Url realUrl : service.getRealServiceUrls()) { for (String replacement : replacementArray) { // We don't want to inject empty string match if (replacement.trim().length() > 0) { Url newUrl = new Url(realUrl.getFullUrl().replaceAll(matchPattern, replacement)); if (!service.hasRealServiceUrl(newUrl)) { newUrlList.add(newUrl); // Note: you should not save or update // the realServiceUrl or service while // iterating through the list itself, or you'll // get // a java.util.ConcurrentModificationException // Wait until 'after' } } } } // Save/update this new Url object list. for (Url newUrl : newUrlList) { service.saveOrUpdateRealServiceUrl(newUrl); } // Now update the service. store.saveOrUpdateService(service); } try { successOrFail.put("success", "URL injecting complete."); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { try { successOrFail.put("fail", "You didn't pass any match or inject URL arguments. "); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } JSONObject responseObject = new JSONObject(); try { responseObject.put("result", successOrFail); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } PrintWriter out = resp.getWriter(); out.println(responseObject.toString()); out.flush(); out.close(); return; }
From source file:net.handle.servlet.RequestAdapter.java
private HandleRecordType[] initTypes(HttpServletRequest request, Settings settings) { HandleRecordType[] theTypes = null;/*from w w w. j a va 2 s. co m*/ String[] rawTypes = request.getParameterValues(settings.getTypeRequestParameterName()); if (rawTypes != null && rawTypes.length > 0) { List<HandleRecordType> typesTransitional = new ArrayList<HandleRecordType>(); for (String s : rawTypes) { HandleRecordType type = HandleRecordType.forName(s); if (type != null) { typesTransitional.add(type); } } if (!(typesTransitional.isEmpty())) { theTypes = typesTransitional.toArray(new HandleRecordType[typesTransitional.size()]); } } return theTypes; }
From source file:com.flaptor.clusterfest.deploy.DeployModule.java
@SuppressWarnings("unchecked") public String doPage(String page, HttpServletRequest request, HttpServletResponse response) { List<NodeDescriptor> nodes = new ArrayList<NodeDescriptor>(); String[] nodesParam = request.getParameterValues("node"); if (nodesParam != null) { for (String idx : nodesParam) { nodes.add(ClusterManager.getInstance().getNodes().get(Integer.parseInt(idx))); }//from w ww .j a v a 2 s .c o m } request.setAttribute("nodes", nodes); if (ServletFileUpload.isMultipartContent(request)) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); String name = null; byte[] content = null; String path = null; // Parse the request try { List<FileItem> items = upload.parseRequest(request); String message = ""; for (FileItem item : items) { String fieldName = item.getFieldName(); if (fieldName.equals("node")) { NodeDescriptor node = ClusterManager.getInstance().getNodes() .get(Integer.parseInt(item.getString())); if (!node.isReachable()) message += node + " is unreachable<br/>"; if (getModuleNode(node) != null) nodes.add(node); else message += node + " is not registered as deployable<br/>"; } if (fieldName.equals("path")) path = item.getString(); if (fieldName.equals("file")) { name = item.getName(); content = IOUtil.readAllBinary(item.getInputStream()); } } List<Pair<NodeDescriptor, Throwable>> errors = deployFiles(nodes, path, name, content); if (errors != null && errors.size() > 0) { request.setAttribute("deployCorrect", false); request.setAttribute("deployErrors", errors); } else request.setAttribute("deployCorrect", true); request.setAttribute("message", message); } catch (Exception e) { throw new RuntimeException(e); } } return "deploy.vm"; }
From source file:com.mockey.ui.ServiceMergeServlet.java
/** * // ww w . j a v a 2 s . c o m * * @param req * basic request * @param resp * basic resp * @throws ServletException * basic * @throws IOException * basic */ @SuppressWarnings("unchecked") public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Boolean originalMode = store.getReadOnlyMode(); store.setReadOnlyMode(true); String[] serviceMergeIdList = req.getParameterValues("serviceIdMergeSource[]"); Enumeration<String> names = (Enumeration<String>) req.getParameterNames(); while (names.hasMoreElements()) { log.debug(names.nextElement()); } Long serviceIdMergeSource = null; Long serviceIdMergeDestination = null; ServiceMergeResults mergeResults = null; Map<String, String> responseMap = new HashMap<String, String>(); try { for (int i = 0; i < serviceMergeIdList.length; i++) { serviceIdMergeSource = new Long(serviceMergeIdList[i]); serviceIdMergeDestination = new Long(req.getParameter("serviceIdMergeDestination")); if (!serviceIdMergeSource.equals(serviceIdMergeDestination)) { Service serviceMergeSource = store.getServiceById(serviceIdMergeSource); Service serviceMergeDestination = store.getServiceById(serviceIdMergeDestination); MockeyXmlFileManager configurationReader = new MockeyXmlFileManager(); mergeResults = configurationReader.mergeServices(serviceMergeSource, serviceMergeDestination, mergeResults, null); } responseMap.put("additions", mergeResults.getAdditionMsg()); responseMap.put("conflicts", mergeResults.getConflictMsg()); } } catch (Exception e) { // Do nothing log.error("Something wrong with merging services.", e); responseMap.put("conflicts", "Unable to merge services. The services selected may be missing or contain bad data. Sorry about this."); } // IF NO CONFLICTS, THEN DELETE OLD SOURCE SERVICES if (mergeResults != null && (mergeResults.getConflictMsgs() == null || mergeResults.getConflictMsgs().isEmpty())) { for (int i = 0; i < serviceMergeIdList.length; i++) { serviceIdMergeSource = new Long(serviceMergeIdList[i]); Service service = store.getServiceById(serviceIdMergeSource); store.deleteService(service); } } resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); String resultingJSON = Util.getJSON(responseMap); out.println(resultingJSON); out.flush(); out.close(); store.setReadOnlyMode(originalMode); return; // AJAX thing. Return nothing at this time. }
From source file:edu.wisc.my.stats.web.GraphingFormController.java
/** * @see edu.wisc.my.stats.web.DynamicMultiPageFormController#getCurrentPageNumber(javax.servlet.http.HttpServletRequest, java.lang.Object, org.springframework.validation.Errors) *///from w w w .j a v a 2s.com @Override protected int getCurrentPageNumber(HttpServletRequest request, Object command, Errors errors) throws Exception { int page = this.getInitialPage(request, command); final String[] values = request.getParameterValues("ISSUBMIT"); if (values == null) { return page; } for (final String value : values) { try { page = Math.max(page, Integer.parseInt(value)); } catch (NumberFormatException nfe) { //Ignore } } return page; }
From source file:cn.vlabs.umt.ui.actions.ManageUserAction.java
public ActionForward removeUser(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*from ww w . j a v a 2 s. co m*/ UserService us = ServiceFactory.getUserService(request); String[] usernames = request.getParameterValues("userids"); us.remove(CommonUtils.stringArray2IntArray(usernames)); return showUsers(mapping, form, request, response); }
From source file:net.handle.servlet.RequestAdapter.java
private int[] initIndices(HttpServletRequest request, Settings settings) { int[] theIndices = null; String[] indicesStringArray = request.getParameterValues(settings.getIndexRequestParameterName()); if (indicesStringArray != null && indicesStringArray.length > 0) { Integer[] indicesTransitional = new Integer[indicesStringArray.length]; for (int i = 0; i < indicesStringArray.length; i++) { try { indicesTransitional[i] = new Integer(indicesStringArray[i]); } catch (NumberFormatException e) { LOG.info(e);//from w w w .j a v a 2 s . co m } } int i = 0; for (Integer integer : indicesTransitional) { if (integer != null) { i++; } } theIndices = new int[i]; i = 0; for (Integer integer : indicesTransitional) { if (integer != null) { theIndices[i] = integer; i++; } } } return theIndices; }
From source file:com.redhat.rhn.frontend.action.channel.PackageNameOverviewAction.java
/** {@inheritDoc} */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*from w w w.j av a2 s . co m*/ String pkgName = request.getParameter("package_name"); String subscribedChannels = request.getParameter("search_subscribed_channels"); String channelFilter = request.getParameter("channel_filter"); String[] channelArches = request.getParameterValues("channel_arch"); request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI()); RequestContext ctx = new RequestContext(request); User user = ctx.getCurrentUser(); List dr = Collections.EMPTY_LIST; if (StringUtils.equals(subscribedChannels, "yes")) { dr = PackageManager.lookupPackageNameOverview(user.getOrg(), pkgName); } else if (!StringUtils.isEmpty(channelFilter) && StringUtils.equals(subscribedChannels, "no") && channelArches == null) { Long filterChannelId = null; try { filterChannelId = Long.parseLong(channelFilter); dr = PackageManager.lookupPackageNameOverviewInChannel(user.getOrg(), pkgName, filterChannelId); } catch (NumberFormatException e) { log.warn("Exception caught, unable to parse channel ID: " + channelFilter); dr = Collections.EMPTY_LIST; } } else if (channelArches != null && channelArches.length > 0) { dr = PackageManager.lookupPackageNameOverview(user.getOrg(), pkgName, channelArches); } request.setAttribute(RequestContext.PAGE_LIST, dr); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); }