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:net.duckling.ddl.web.controller.DashboardController.java
@RequestMapping(params = "func=resortTeam") @ResponseBody/* w ww . j a va 2 s. c om*/ public int resort(HttpServletRequest request) { String ids[] = request.getParameterValues("resortedIds[]"); VWBContext context = VWBContext.createContext(request, UrlPatterns.DASHBOARD); String uid = context.getCurrentUID(); return teamMemberService.updateTeamsSequence(uid, ids); }
From source file:ke.co.tawi.babblesms.server.servlet.contacts.AddContacts.java
/** * * @param request//from www. j a va 2s .co m * @param response * @throws ServletException * @throws IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userPath = request.getServletPath(); HttpSession session = request.getSession(false); // if add contacts is called if (userPath.equals("/account/addcontact")) { String[] emailArray = request.getParameterValues("email[]"); String[] phonenumArray = request.getParameterValues("phonenum[]"); String[] networkArray = request.getParameterValues("network[]"); String contactname = request.getParameter("contname"); String groupid = request.getParameter("groupid"); String statusuuid = request.getParameter("statusuuid"); String accountuuid = request.getParameter("accountuuid"); Set<String> mySet = new HashSet<String>(Arrays.asList(emailArray)); Set<String> mySet2 = new HashSet<String>(Arrays.asList(phonenumArray)); int duplicateemail = emailArray.length - mySet.size(); int duplicatephone = phonenumArray.length - mySet2.size(); // No First Name provided if ((StringUtils.isBlank(contactname)) || (emailArray.length == 0) || (phonenumArray.length == 0) || (networkArray.length == 0)) { session.setAttribute(SessionConstants.ADD_ERROR, ERROR_NO_NAME); } else if (!validemails(emailArray)) { session.setAttribute(SessionConstants.ADD_ERROR, ERROR_INVALID_EMAIL); } else if (existsEmail(emailArray)) { session.setAttribute(SessionConstants.ADD_ERROR, ERROR_EMAIL_EXISTS); } else if (duplicateemail >= 1) { session.setAttribute(SessionConstants.ADD_ERROR, ERROR_DUPLICATE_EMAIL); } else if (duplicatephone >= 1) { session.setAttribute(SessionConstants.ADD_ERROR, ERROR_PUBLICATE_PHONE); } /*else if (existsPhone(phonenumArray)) { session.setAttribute(SessionConstants.ADD_ERROR, ERROR_PHONE_EXISTS); }*/ else { session.setAttribute(SessionConstants.ADD_SUCCESS, ADD_SUCCESS); ct = new Contact(); ct.setName(contactname); ct.setStatusUuid(statusuuid); ct.setAccountUuid(accountuuid); if (ctDAO.putContact(ct)) { } else { session.setAttribute(SessionConstants.ADD_ERROR, "Contact creation Failed."); } //get contact bean to update cache String uuid = ct.getUuid(); //ct = ctDAO.getContactByName(contactname); ct = ctDAO.getContact(uuid); //logger.info(ct + " added sucessfully"); // mgr.getCache(CacheVariables.CACHE_CONTACTS_BY_UUID).put(new Element(ct.getUuid(), ct)); //loop emails for (String email2 : emailArray) { mail = new Email(); mail.setAddress(email2); mail.setContactuuid(ct.getUuid()); //mail.setStatusuuid(statusuuid); emailDAO.putEmail(mail); //get uuid to update cache mail = emailDAO.getEmail(email2); //logger.info(mail + " added sucessfully"); mgr.getCache(CacheVariables.CACHE_EMAIL_BY_UUID).put(new Element(mail.getUuid(), mail)); } //loop phonenumbers int count = 0; for (String phonenum : phonenumArray) { phn = new Phone(); phn.setPhonenumber(phonenum); phn.setContactUuid(ct.getUuid()); phn.setNetworkuuid(networkArray[count]); //phn.setStatusuuid(statusuuid); phoneDAO.putPhone(phn); //updatecache with correct uuid phn = phoneDAO.getPhone(phonenum); //logger.info(phn + " added sucessfully"); mgr.getCache(CacheVariables.CACHE_PHONE_BY_UUID).put(new Element(phn.getUuid(), phn)); count++; } // ContactGroup cg = new ContactGroup(); // cg.setAccountsuuid(accountuuid); // cg.setCgroupuuid(groupid); //cg.setContactuuid(ct.getUuid()); //cgDAO.putContactGroup(cg); //logger.info(cg + " added sucessfully"); //mgr.getCache(CacheVariables.CACHE_CONTACT_GROUP_BY_UUID).put(new Element(cg.getUuid(), cg)); //response.sendRedirect("account/contact.jsp"); } response.sendRedirect("addcontact.jsp"); //userPath = "addcontact"; } else if (userPath.equals("/account/editEmail")) { String email = request.getParameter("email"); String emailuuid = request.getParameter("emailuuid"); String contactname = request.getParameter("contname"); String contactuuid = request.getParameter("contactuuid"); //ctDAO.updateContact(contactuuid, contactname); /*if (emailDAO.updateEmail(emailuuid, email)) { session.setAttribute(SessionConstants.UPDATE_SUCCESS, "Update was successful."); } else { session.setAttribute(SessionConstants.UPDATE_ERROR, "Update Failed."); }*/ response.sendRedirect("contactemail.jsp"); //userPath = "contactemail"; } else if (userPath.equals("/account/editcontact")) { String phone = request.getParameter("phonenum"); String phoneuuid = request.getParameter("phoneuuid"); String contactname = request.getParameter("contname"); String contactuuid = request.getParameter("contactuuid"); /* ctDAO.updateContact(contactuuid, contactname); emailDAO.updateEmail(emailuuid, email); if (phoneDAO.updatePhone(phoneuuid, phone)) { session.setAttribute(SessionConstants.UPDATE_SUCCESS, "Update successful."); } else { session.setAttribute(SessionConstants.UPDATE_ERROR, "Update failed."); }*/ response.sendRedirect("contact.jsp"); //userPath = "contact"; } else if (userPath.equals("/account/deletecontact")) { String contactuuid = request.getParameter("contactuuid"); //String emailuuid = request.getParameter("emailuuid"); //String phone = request.getParameter("phonenum"); String phoneuuid = request.getParameter("phoneuuid"); /* if(phoneDAO.deletePhone(phoneuuid)){ ctDAO.deleteContact(contactuuid); session.setAttribute(SessionConstants.DELETE_SUCCESS, "Deletion successful."); } else{ session.setAttribute(SessionConstants.DELETE_ERROR, "Deletion failed."); }*/ response.sendRedirect("contact.jsp"); //userPath = "contact"; } else if (userPath.equals("/account/deleteemail")) { String contactuuid = request.getParameter("contactuuid"); String emailuuid = request.getParameter("emailuuid"); /* if(emailDAO.deleteEmail(emailuuid)){ // ctDAO.deleteContact(contactuuid); session.setAttribute(SessionConstants.DELETE_SUCCESS, "Deletion successful."); } else{ session.setAttribute(SessionConstants.DELETE_ERROR, "Deletion failed."); }*/ response.sendRedirect("contactemail.jsp"); //userPath = "contactemail"; } // use RequestDispatcher to forward request internally /* String url = userPath + ".jsp"; try { request.getRequestDispatcher(url).forward(request, response); } catch (ServletException | IOException ex) { } */ }
From source file:com.jaspersoft.jasperserver.rest.services.RESTResources.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // Extract the uri from which list the resources... String uri = restUtils.extractRepositoryUri(req.getPathInfo()); // "resources" is a REST service path if (uri == null || "resources".equals(uri)) uri = "/"; // Extract the criteria String queryString = req.getParameter("q"); if (queryString == null || queryString.length() == 0) { queryString = null;/*from w w w . ja v a2 s .co m*/ } List<String> resourceTypes = new ArrayList<String>(); String[] resourceTypesArray = req.getParameterValues("type"); if (resourceTypesArray != null) { resourceTypes.addAll(Arrays.asList(resourceTypesArray)); } Iterator<String> itr = resourceTypes.iterator(); while (itr.hasNext()) { String resourceType = itr.next(); if (!(resourceType != null && resourceType.length() != 0)) { itr.remove(); } } int limit = 0; if (req.getParameter("limit") != null && req.getParameter("limit").length() > 0) { try { limit = Integer.parseInt(req.getParameter("limit")); if (limit < 0) throw new Exception(); } catch (Throwable ex) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid value set for parameter limit."); return; } } int startIndex = 0; if (req.getParameter("startIndex") != null && req.getParameter("startIndex").length() > 0) { try { startIndex = Integer.parseInt(req.getParameter("startIndex")); if (startIndex < 0) throw new Exception(); } catch (Throwable ex) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid value set for parameter startIndex."); return; } } List list = new ArrayList(); // If not a search, just list the content of the specified folder... if (queryString == null && (resourceTypes.size() == 0)) { list = resourcesListRemoteService.listResources(uri, limit); } else { boolean recursive = false; if (req.getParameter("recursive") != null && (req.getParameter("recursive").equals("1") || req.getParameter("recursive").equalsIgnoreCase("true") || req.getParameter("recursive").equalsIgnoreCase("yes"))) { recursive = true; } //list = service.getResources(criteria, limit, resourceTypes == null ? null : Arrays.asList(resourceTypes)); list = resourcesListRemoteService.getResources(uri, queryString, resourceTypes.size() == 0 ? null : resourceTypes, recursive, limit, startIndex); } StringBuilder xml = new StringBuilder(); Marshaller m = new Marshaller(); xml.append("<resourceDescriptors>\n"); if (list != null && !list.isEmpty()) for (Object rd : list) { // we assume the objects are actually resource descriptors... xml.append(m.writeResourceDescriptor((ResourceDescriptor) rd)); } xml.append("</resourceDescriptors>"); restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, xml.toString()); }
From source file:com.me.Controller.AddBookController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView(); String action = request.getParameter("action"); if (action.equals("get")) { String number = request.getParameter("noOfBooks"); int noOfBooks = Integer.parseInt(number); if (noOfBooks > 0) { mav.addObject("numberBooks", noOfBooks); mav.setViewName("Books"); }// w w w . jav a2 s. co m } else if (action.equals("post")) { DAO dao = new DAO(); Connection conn = null; PreparedStatement preparedStatement = null; try { conn = dao.getConnection(); String[] isbn = request.getParameterValues("isbn"); String[] title = request.getParameterValues("title"); String[] authors = request.getParameterValues("authors"); String[] price = request.getParameterValues("Price"); String insertQuery = "insert into books(isbn,title,authors,price)" + "values(?,?,?,?)"; int count = 0; for (int i = 0; i < isbn.length; i++) { preparedStatement = conn.prepareStatement(insertQuery); preparedStatement.setString(1, isbn[i]); preparedStatement.setString(2, title[i]); preparedStatement.setString(3, authors[i]); preparedStatement.setFloat(4, Float.parseFloat(price[i])); int result = preparedStatement.executeUpdate(); count++; } mav.addObject("noOfRecords", count); mav.setViewName("Result"); } finally { dao.closeConnection(conn); dao.closeStatement(preparedStatement); } } return mav; }
From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java
/** * /* w ww. j a v a 2s.co m*/ * @param request * @return */ private static String preassembleQueryString(HttpServletRequest request) { //System.out.println("\tin preassembleQueryString"); String queryString = ""; queryString += "q=*:*&json.nl=map&start=0&rows=" + 300 + "&fq=type:File"; if (request.getParameter("shardType").equals("solrconfig")) { queryString = "qt=/distrib&" + queryString; } else { queryString = "shards=" + request.getParameter("shardsString") + "&" + queryString; } if (request.getParameter("showAll").equals("false")) { //get the 'fq' params from the servlet query string here String[] fqParams = request.getParameterValues("fq[]"); //get the 'q' param from the servlet query string here //String qParam = request.getParameter("q"); if (fqParams != null) { //append the 'fq' params to the query string for (int i = 0; i < fqParams.length; i++) { String fqParam = fqParams[i]; queryString += "&fq=" + fqParam; } } } return queryString; }
From source file:io.kahu.hawaii.rest.AbstractController.java
protected RequestLogBuilder requestLog() { String method = new Throwable().getStackTrace()[1].getMethodName(); String type = logTypePrefix + "." + method; RequestLogBuilder builder = new RequestLogBuilder(logManager, type); try {/*from w w w. ja v a 2 s. com*/ ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = sra.getRequest(); // path variables Map<String, String> pathVariables = (Map<String, String>) request .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); if (pathVariables != null) { for (Map.Entry<String, String> entry : pathVariables.entrySet()) { builder.param(entry.getKey(), entry.getValue()); } } // request parameters Enumeration<?> requestParameters = request.getParameterNames(); while (requestParameters.hasMoreElements()) { String key = (String) requestParameters.nextElement(); String[] values = request.getParameterValues(key); builder.param(key, values); } } catch (Throwable t) { logManager.warn(CoreLoggers.SERVER, "Unable to log request", t); // ignore } return builder.excludeParam("_"); }
From source file:mx.edu.um.mateo.general.web.UsuarioController.java
@Transactional @RequestMapping(value = "/actualiza", method = RequestMethod.POST) public String actualiza(HttpServletRequest request, @Valid Usuario usuario, BindingResult bindingResult, Errors errors, Model modelo, RedirectAttributes redirectAttributes, @RequestParam(required = false) String[] centrosDeCostoIds) { if (bindingResult.hasErrors()) { log.error("Hubo algun error en la forma, regresando"); List<Rol> roles = obtieneRoles(); modelo.addAttribute("roles", roles); return "admin/usuario/edita"; }// w ww . j a v a 2 s.c om try { String[] roles = request.getParameterValues("roles"); if (roles == null || roles.length == 0) { roles = new String[] { "ROLE_USER" }; } Long almacenId = (Long) request.getSession().getAttribute("almacenId"); usuario = usuarioDao.actualiza(usuario, almacenId, roles, centrosDeCostoIds); } catch (ConstraintViolationException e) { log.error("No se pudo crear al usuario", e); errors.rejectValue("username", "campo.duplicado.message", new String[] { "username" }, null); List<Rol> roles = obtieneRoles(); modelo.addAttribute("roles", roles); return "admin/usuario/edita"; } redirectAttributes.addFlashAttribute("message", "usuario.actualizado.message"); redirectAttributes.addFlashAttribute("messageAttrs", new String[] { usuario.getUsername() }); return "redirect:/admin/usuario/ver/" + usuario.getId(); }
From source file:com.globalsight.everest.projecthandler.MachineTranslateAdapter.java
private void setExtendInfo(HttpServletRequest p_request, MachineTranslationProfile mtProfile) { String[] dirNames = p_request.getParameterValues("dirName"); if (dirNames == null || dirNames.length == 0) return;//from w w w. j a v a 2 s .com Set<MachineTranslationExtentInfo> exInfo = mtProfile.getExInfo(); if (exInfo == null || exInfo.size() < dirNames.length) { exInfo = exInfo == null ? new HashSet<MachineTranslationExtentInfo>() : exInfo; for (int i = exInfo.size(); i < dirNames.length; i++) { exInfo.add(new MachineTranslationExtentInfo()); } mtProfile.setExInfo(exInfo); } Iterator<MachineTranslationExtentInfo> it = exInfo.iterator(); int i = 0; while (it.hasNext()) { MachineTranslationExtentInfo mtExtentInfo = it.next(); String[] key = dirNames[i].split("@"); mtExtentInfo.setSelfInfo(key); mtExtentInfo.setMtProfile(mtProfile); i++; } }
From source file:jp.mathes.databaseWiki.web.DbwServlet.java
@SuppressWarnings("unchecked") private void redirect(final String baseURL, final HttpServletRequest req, final HttpServletResponse resp, final String db, final String table, String name, final boolean withParameters) throws IOException { name = URLEncoder.encode(name, "UTF-8"); StringBuilder paramStr = new StringBuilder(); if (withParameters) { for (String paramName : Collections.list((Enumeration<String>) req.getParameterNames())) { if (paramName.startsWith("_") || paramName.equals("name")) { continue; }/* w w w . ja v a 2s. co m*/ for (String value : req.getParameterValues(paramName)) { paramStr.append(paramName).append("=").append(value).append("&"); } } } if (paramStr.length() > 0) { resp.sendRedirect( String.format(baseURL + "?%s", req.getContextPath(), db, table, name, paramStr.toString())); } else { resp.sendRedirect(String.format(baseURL, req.getContextPath(), db, table, name)); } }
From source file:de.jwi.jfm.servlets.Controller.java
private String handleQuery(HttpServletRequest request, HttpServletResponse response, Folder folder) throws OutOfSyncException, IOException { String rc = ""; HttpSession session = request.getSession(); String target = null;/*from ww w. ja v a 2 s . c o m*/ int action = NOP_ACTION; String[] selectedfiles = request.getParameterValues("index"); String logout = request.getParameter("logout"); if ("t".equals(logout)) { request.getSession().invalidate(); return ""; } String sum = request.getParameter("sum"); if ("t".equals(sum)) { folder.sum(); return ""; } String sort = request.getParameter("sort"); if ("nd".equals(sort)) { folder.sort(Folder.SORT_NAME_DOWN); return ""; } else if ("nu".equals(sort)) { folder.sort(Folder.SORT_NAME_UP); return ""; } else if ("su".equals(sort)) { folder.sort(Folder.SORT_SIZE_UP); return ""; } else if ("sd".equals(sort)) { folder.sort(Folder.SORT_SIZE_DOWN); return ""; } else if ("du".equals(sort)) { folder.sort(Folder.SORT_DATE_UP); return ""; } else if ("dd".equals(sort)) { folder.sort(Folder.SORT_DATE_DOWN); return ""; } OutputStream out = null; String command = request.getParameter("command"); if ("Mkdir".equals(command)) { target = request.getParameter("newdir"); action = MKDIR_ACTION; } if ("GetURL".equals(command)) { target = request.getParameter("url"); action = GETURL_ACTION; } else if ("Delete".equals(command)) { action = DELETE_ACTION; } else if ("Rename to".equals(command)) { target = request.getParameter("renameto"); action = RENAME_ACTION; } else if ("Unzip".equals(command)) { action = UNZIP_ACTION; } else if ("ZipDownload".equals(command)) { action = ZIP_ACTION; response.setContentType("application/zip"); response.setHeader("Content-Disposition", "inline; filename=\"jFMdownload.zip\""); out = response.getOutputStream(); } else if ("Copy to".equals(command)) { target = request.getParameter("copyto"); action = COPY_ACTION; } else if ("Move to".equals(command)) { target = request.getParameter("moveto"); action = MOVE_ACTION; } else if ("Chmod to".equals(command)) { target = request.getParameter("chmodto"); action = CHMOD_ACTION; } else if ("DeleteRecursively".equals(command)) { target = request.getParameter("confirm"); action = DELETE_RECURSIVE_ACTION; } else if ("FtpUpload to".equals(command)) { target = request.getParameter("ftpto"); action = FTPUP_ACTION; } else if ("Join".equals(command)) { action = JOIN_ACTION; } else if ("cut".equals(command)) { action = CLIPBOARD_CUT_ACTION; } else if ("copy".equals(command)) { action = CLIPBOARD_COPY_ACTION; } else if ("paste".equals(command)) { action = CLIPBOARD_PASTE_ACTION; } else if ("clear".equals(command)) { action = CLIPBOARD_CLEAR_ACTION; } if (NOP_ACTION == action) { return ""; } try { rc = folder.action(action, out, selectedfiles, target, session); } catch (SecurityException e) { rc = "SecurityException: " + e.getMessage(); return rc; } folder.load(); return rc; }