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:JoinGameServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Enumeration paramNames = request.getParameterNames(); String params[] = new String[3]; int i = 0;/*w w w.ja v a 2 s. c o m*/ while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); //System.out.println("ParamName : " +paramName); String[] paramValues = request.getParameterValues(paramName); params[i] = paramValues[0]; //System.out.println("ParamValue : " +params[i]); i++; } //System.out.println("param0->"+params[0]); //System.out.println("param1->"+params[1]); //param0->gameid,param1->name DatabaseHandler db = new DatabaseHandler(); conn = db.makeConnection(); String query = "SELECT * FROM game WHERE id=" + params[0]; //System.out.println(query); PreparedStatement prStmt; try { prStmt = conn.prepareStatement(query); ResultSet rs = prStmt.executeQuery(); if (rs.next()) { String count = rs.getString("playercount"); count = String.valueOf(Integer.parseInt(count) + 1); String qry = "UPDATE game SET nameplayer" + count + "=\"" + params[1] + "\",playercount=\"" + count + "\" WHERE id=\"" + params[0] + "\""; //System.out.println(qry); stmt = conn.createStatement(); int updatedRows = stmt.executeUpdate(qry); if (updatedRows == 1) { json.put("reply", "done"); json.put("actionid", count); //setting next player action to 1 to start bet if (Integer.parseInt(count) == 4) { qry = "UPDATE game SET turn=1,nextactionuserid=1 WHERE id=\"" + params[0] + "\""; stmt.execute(qry); } } else { json.put("reply", "undone"); } } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json.toString()); } catch (SQLException ex) { Logger.getLogger(JoinGameServlet.class.getName()).log(Level.SEVERE, null, ex); } db.closeAllConnections(conn, stmt); }
From source file:info.magnolia.cms.filters.CommonsFileUploadMultipartRequestFilter.java
/** * Add the <code>FileItem</code> as a paramter into the <code>MultipartForm</code>. *//* w w w . jav a 2s . c o m*/ private void addField(HttpServletRequest request, FileItem item, MultipartForm form) { String name = item.getFieldName(); String value; try { String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8"); value = item.getString(encoding); } catch (UnsupportedEncodingException ex) { value = item.getString(); } form.addParameter(name, value); String[] values = request.getParameterValues(name); if (values != null) { form.addparameterValues(name, values); } }
From source file:com.jaeksoft.searchlib.renderer.filter.RendererFilterQueries.java
public void applyServletRequest(HttpServletRequest servletRequest) { if (servletRequest.getParameter("fqc") != null) filterQueries.clear();/* w w w . j ava 2s .co m*/ Enumeration<String> en = servletRequest.getParameterNames(); if (en != null) { while (en.hasMoreElements()) { String parm = en.nextElement(); if (parm.startsWith("fqa.")) addTerm(parm.substring(4), servletRequest.getParameterValues(parm)); if (parm.startsWith("fqr.")) removeTerm(parm.substring(4), servletRequest.getParameterValues(parm)); if (parm.startsWith("fq.")) setQuery(parm.substring(4), servletRequest.getParameter(parm)); } } }
From source file:org.openmrs.web.controller.concept.ConceptClassListController.java
/** * The onSubmit function receives the form/command object that was modified by the input form * and saves it to the db// w ww . j av a 2 s .com * * @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()) { StringBuilder success = new StringBuilder(); String error = ""; MessageSourceAccessor msa = getMessageSourceAccessor(); String[] conceptClassList = request.getParameterValues("conceptClassId"); if (conceptClassList != null) { ConceptService cs = Context.getConceptService(); String deleted = msa.getMessage("general.deleted"); String notDeleted = msa.getMessage("ConceptClass.cannot.delete"); for (String cc : conceptClassList) { try { cs.purgeConceptClass(cs.getConceptClass(Integer.valueOf(cc))); if (!"".equals(success.toString())) { success.append("<br/>"); } success.append(cc).append(" ").append(deleted); } catch (DataIntegrityViolationException e) { error = handleConceptClassIntegrityException(e, error, notDeleted); } catch (APIException e) { error = handleConceptClassIntegrityException(e, error, notDeleted); } } } else { error = msa.getMessage("ConceptClass.select"); } view = getSuccessView(); if (!"".equals(success.toString())) { httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success.toString()); } if (!"".equals(error)) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error); } } return new ModelAndView(new RedirectView(view)); }
From source file:com.krawler.esp.handlers.ProfileHandler.java
public static void update_profile_status(Session session, HttpServletRequest request) throws ServiceException, SessionExpiredException { try {//ww w.j av a2 s .c o m String[] ids = request.getParameterValues("emp_ids"); for (int i = 0; i < ids.length; i++) { Empprofile prof = (Empprofile) session.load(Empprofile.class, ids[i]); prof.setStatus("Approved"); prof.setUpdated_by(AuthHandler.getUserid(request)); prof.setUpdated_on(new Date()); session.saveOrUpdate(prof); //ProfileHandler.insertAuditLog(session, AuditAction.PROFILE_APPROVED, "User " + AuthHandler.getFullName(session, AuthHandler.getUserid(request)) + " has approved " + AuthHandler.getFullName(session, prof.getUserID()),request); } } catch (HibernateException ex) { throw ServiceException.FAILURE("ProfileHandler.EmpProfilestatus", ex); } catch (SessionExpiredException ex) { throw ServiceException.FAILURE("ProfileHandler.EmpProfilestatus", ex); } }
From source file:com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.java
public void setParameters(HttpServletRequest request) { parameters = new HashMap(); Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String name = (String) parameterNames.nextElement(); parameters.put(name, request.getParameterValues(name)); }/* w ww.j a v a 2 s. com*/ }
From source file:com.virtusa.akura.attendance.controller.DailyAttendanceController.java
/** * method to save or update student attendance object. * /*w ww . j av a 2s . com*/ * @param request Http request. * @param map model map to set data. * @return String value of jsp page to direct. * @throws AkuraAppException throw exception if occur. */ @RequestMapping(method = RequestMethod.POST, value = REQ_VALUE_SAVEORUPDATE_STUDENT_ATTENDANCE) public String saveorupdateStudentAttendance(HttpServletRequest request, ModelMap map) throws AkuraAppException { String[] studentID = request.getParameterValues(STUDENT_ID_LIST); // selected class String classGradeId = request.getParameter(SELECT); // selected grade String date = request.getParameter(DATE); // get the daily student attendance list for given date and class List<DailyStudentAttendance> dailyStudentAttendanceList = dailyAttendanceService .getStudentAttandanceList(DateUtil.getParseDate(date), Integer.parseInt(classGradeId)); List<String> pastAttendanceList = new ArrayList<String>(); // get the present students id list for (DailyStudentAttendance dailyAttendanceList : dailyStudentAttendanceList) { pastAttendanceList.add(dailyAttendanceList.getStudentId().toString()); } try { if (studentID != null) { @SuppressWarnings("unchecked") // get the absent student list List<String> toBeRomoved = ListUtils.subtract((pastAttendanceList), Arrays.asList(studentID)); @SuppressWarnings("unchecked") // get the present student list List<String> toBeAdd = ListUtils.subtract(Arrays.asList(studentID), pastAttendanceList); // add present students if (!toBeAdd.isEmpty()) { String timeIn = PropertyReader.getPropertyValue(SYSTEM_CONFIG, DEFAULT_TIME_IN); String timeOut = PropertyReader.getPropertyValue(SYSTEM_CONFIG, DEFAULT_TIME_OUT); List<DailyStudentAttendance> saveList = new ArrayList<DailyStudentAttendance>(); for (String presentStudentId : toBeAdd) { DailyStudentAttendance dailyStudentAttendance = new DailyStudentAttendance(); dailyStudentAttendance.setStudentId(Integer.valueOf(presentStudentId)); dailyStudentAttendance.setDate(DateUtil.getParseDate(date)); dailyStudentAttendance.setTimeIn(timeIn); dailyStudentAttendance.setTimeOut(timeOut); saveList.add(dailyStudentAttendance); } dailyAttendanceService.saveDailyStudentAttendance(saveList); } // remove absent students if (!toBeRomoved.isEmpty()) { deleteStudentAttendance(date, toBeRomoved); } return searchStudentAttendance(request, map); } else if (studentID == null && (!dailyStudentAttendanceList.isEmpty())) { deleteStudentAttendance(date, pastAttendanceList); return searchStudentAttendance(request, map); } } catch (AkuraAppException e) { if (e.getCause() instanceof DataIntegrityViolationException) { String message = new ErrorMsgLoader().getErrorMessage(ATTENDANCE_SAVE_FAIL); map.addAttribute(MESSAGE, message); return ATTENDANCE_DAILY_ATTENDANCE; } else { throw e; } } return searchStudentAttendance(request, map); }
From source file:com.swdouglass.joid.server.OpenIdServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuilder sb = new StringBuilder(); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String[] values = request.getParameterValues(name); if (values.length == 0) { throw new IOException("Empty value not allowed: " + name + " has no value"); }/* w w w . ja va 2 s . c o m*/ try { sb.append(URLEncoder.encode(name, "UTF-8") + "=" + URLEncoder.encode(values[0], "UTF-8")); } catch (UnsupportedEncodingException ex) { throw new IOException(ex.toString()); } if (e.hasMoreElements()) { sb.append("&"); } } doQuery(sb.toString(), request, response); }
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 sendMessage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String[] accounts = request.getParameterValues("username"); if (accounts != null && accounts.length == 1) { return CoreUtil.addParameterToForward(mapping.findForward("sendMessage"), "users", accounts[0]); } return list(mapping, form, request, response); }
From source file:org.openmrs.notification.web.controller.AlertListController.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 . ja v a 2 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(); Locale locale = Context.getLocale(); if (Context.isAuthenticated()) { AlertService as = Context.getAlertService(); MessageSourceAccessor msa = getMessageSourceAccessor(); String msg = ""; // expire the selected alerts String[] alertIds = request.getParameterValues("alertId"); if (alertIds != null) { for (String alertIdString : alertIds) { Integer alertId = Integer.parseInt(alertIdString); Alert a = as.getAlert(alertId); a.setDateToExpire(new Date()); as.saveAlert(a); } msg = msa.getMessage("Alert.expired", new Object[] { alertIds.length }, locale); } else { msg = msa.getMessage("Alert.select"); } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, msg); return new ModelAndView(new RedirectView(getSuccessView())); } // The user isn't authenticated or their session has expired return showForm(request, response, errors); }