List of usage examples for org.springframework.web.bind ServletRequestUtils getIntParameter
public static int getIntParameter(ServletRequest request, String name, int defaultVal)
From source file:com.netease.channel.util.ServletUtils.java
/** * Get an int parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it * was supplied./*from w ww .j a v a 2 s . c o m*/ * * @param request * current HTTP request * @param name * the name of the parameter * @param defaultVal * the default value to use as fallback */ public static int getInt(ServletRequest request, String name, int defaultVal) { return ServletRequestUtils.getIntParameter(request, name, defaultVal); }
From source file:org.openmrs.module.logmanager.web.util.WebUtils.java
/** * Gets an int parameter from the request that is being "remembered" in the session * @param request the http request//from w w w. j a va 2 s. c om * @param name the name of the parameter * @param def the default value of the parameter * @param sessionPrefix the prefix to generate session attribute from parameter name * @return the parameter value */ public static int getSessionedIntParameter(HttpServletRequest request, String name, int def, String sessionPrefix) { HttpSession session = request.getSession(); int val = def; // If specified in request, read that and store in session if (request.getParameter(name) != null) { val = ServletRequestUtils.getIntParameter(request, name, def); session.setAttribute(sessionPrefix + name, val); } // Otherwise look for a matching attribute in the session else { Integer sessionVal = (Integer) session.getAttribute(sessionPrefix + name); if (sessionVal != null) val = sessionVal; } return val; }
From source file:com.googlecode.psiprobe.controllers.sql.QueryHistoryItemController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int sqlId = ServletRequestUtils.getIntParameter(request, "sqlId", -1); HttpSession sess = request.getSession(false); if (sess != null) { DataSourceTestInfo sessData = (DataSourceTestInfo) sess .getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR); if (sessData != null) { List queryHistory = sessData.getQueryHistory(); if (queryHistory != null) { try { String sql = (String) queryHistory.get(sqlId); response.setCharacterEncoding("UTF-8"); response.getWriter().print(sql); } catch (IndexOutOfBoundsException e) { logger.error("Cannot find a query history entry for history item id = " + sqlId); }/*from ww w.ja v a 2s . c o m*/ } } } return null; }
From source file:com.googlecode.psiprobe.controllers.sql.CachedRecordSetController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int rowsPerPage = ServletRequestUtils.getIntParameter(request, "rowsPerPage", 0); List results = null;/* www . j a v a2 s .co m*/ int rowsAffected = 0; HttpSession sess = request.getSession(false); if (sess == null) { request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.cachedResultSet.failure")); logger.error("Cannot retrieve a cached result set. Http session is NULL."); } else { DataSourceTestInfo sessData = (DataSourceTestInfo) sess .getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR); if (sessData == null) { request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.cachedResultSet.failure")); logger.error("Cannot retrieve a cached result set. " + DataSourceTestInfo.DS_TEST_SESS_ATTR + " session attribute is NULL."); } else { synchronized (sess) { sessData.setRowsPerPage(rowsPerPage); } results = sessData.getResults(); if (results == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.cachedResultSet.failure")); logger.error("Cached results set is NULL."); } else { rowsAffected = results.size(); } } } ModelAndView mv = new ModelAndView(getViewName(), "results", results); mv.addObject("rowsAffected", String.valueOf(rowsAffected)); mv.addObject("rowsPerPage", String.valueOf(rowsPerPage)); return mv; }
From source file:psiprobe.controllers.sql.QueryHistoryItemController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int sqlId = ServletRequestUtils.getIntParameter(request, "sqlId", -1); HttpSession sess = request.getSession(false); if (sess != null) { DataSourceTestInfo sessData = (DataSourceTestInfo) sess .getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR); if (sessData != null) { List<String> queryHistory = sessData.getQueryHistory(); if (queryHistory != null) { try { String sql = queryHistory.get(sqlId); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.getWriter().print(sql); } catch (IndexOutOfBoundsException e) { logger.error("Cannot find a query history entry for history item id = {}", sqlId); logger.trace("", e); }//from w ww . j a va 2 s .c om } } } return null; }
From source file:psiprobe.controllers.sql.CachedRecordSetController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int rowsPerPage = ServletRequestUtils.getIntParameter(request, "rowsPerPage", 0); List<Map<String, String>> results = null; int rowsAffected = 0; HttpSession sess = request.getSession(false); if (sess == null) { request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.cachedResultSet.failure")); logger.error("Cannot retrieve a cached result set. Http session is NULL."); } else {/*from ww w .j av a 2 s. c o m*/ DataSourceTestInfo sessData = (DataSourceTestInfo) sess .getAttribute(DataSourceTestInfo.DS_TEST_SESS_ATTR); if (sessData == null) { request.setAttribute("errorMessage", getMessageSourceAccessor().getMessage("probe.src.dataSourceTest.cachedResultSet.failure")); logger.error("Cannot retrieve a cached result set. {} session attribute is NULL.", DataSourceTestInfo.DS_TEST_SESS_ATTR); } else { synchronized (sess) { sessData.setRowsPerPage(rowsPerPage); } results = sessData.getResults(); if (results == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.cachedResultSet.failure")); logger.error("Cached results set is NULL."); } else { rowsAffected = results.size(); } } } ModelAndView mv = new ModelAndView(getViewName(), "results", results); mv.addObject("rowsAffected", String.valueOf(rowsAffected)); mv.addObject("rowsPerPage", String.valueOf(rowsPerPage)); return mv; }
From source file:org.openmrs.module.appointmentscheduling.web.controller.AppointmentsPortletController.java
@Override protected void populateModel(HttpServletRequest request, Map<String, Object> model) { int patientId = ServletRequestUtils.getIntParameter(request, "patientId", 0); List<Appointment> patientAppointments = null; if (Context.isAuthenticated()) { Patient patient = Context.getPatientService().getPatient(patientId); AppointmentService appointmentService = Context.getService(AppointmentService.class); if (patient != null) { patientAppointments = appointmentService.getAppointmentsOfPatient(patient); }//from ww w. java 2 s. com } model.put("appointmentList", patientAppointments); model.put("patientId", patientId); }
From source file:no.dusken.aranea.admin.control.AddRelationPageController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { //getting the referencepage Long pageID = ServletRequestUtils.getLongParameter(request, "referencePage", 0); Page referencePage = pageService.getEntity(pageID); int numberToadd = ServletRequestUtils.getIntParameter(request, "nPages", 0); for (int i = 0; i < numberToadd; i++) { //checking if pageI is selected String nextPage = "page" + i; Long pID = ServletRequestUtils.getLongParameter(request, nextPage, 0); Page p = null;/*from w ww . j ava2s . c om*/ if (pID != 0) { p = pageService.getEntity(pID); } if (p != null && !referencePage.isRelatedTo(p)) { String description1 = ServletRequestUtils.getStringParameter(request, "description1" + nextPage, ""); String description2 = ServletRequestUtils.getStringParameter(request, "description2" + nextPage, ""); boolean onFrontPage = ServletRequestUtils.getBooleanParameter(request, "onFrontPage", false); PageRelation relation = new PageRelation(referencePage, description1, p, description2, onFrontPage); pageRelationService.saveOrUpdate(relation); } } return new ModelAndView("redirect:editPageRelation.do?referencePage=" + referencePage.getID()); }
From source file:no.dusken.aranea.control.ImageController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); // get parameters from request int maxHeight = ServletRequestUtils.getIntParameter(request, "maxheight", 0); int maxWidth = ServletRequestUtils.getIntParameter(request, "maxwidth", 0); Long ID = ServletRequestUtils.getLongParameter(request, "ID", 0L); // the image file to view File imageFile = null;/* ww w. j av a2 s . c om*/ // get the image log.debug("Asking for image height: {} width: {}, ID: {}", new Object[] { maxHeight, maxWidth, ID }); Image i = imageService.getEntity(ID); if (i != null) { imageFile = imageUtils.getImageFile(i); } if (imageFile == null || !imageFile.exists()) { throw new PageNotFoundException("Imagefile with id " + ID + " not found!"); } if (maxHeight > 0 || maxWidth > 0) { // do resize imageFile = imageUtils.resizeImage(imageFile, maxWidth, maxHeight); } map.put("file", imageFile); return new ModelAndView("fileView", map); }
From source file:no.dusken.aranea.admin.control.ImageFileController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); Long ID = ServletRequestUtils.getRequiredLongParameter(request, "ID"); Image imageFile = imageFileService.getEntity(ID); if (imageFile == null) { // wrong or missing ID throw new Exception("Image file with ID " + ID + " not found."); }/*from w ww. j a v a 2 s . c om*/ File file = new File(resourceDir + imageFile.getUrl()); Integer height = ServletRequestUtils.getIntParameter(request, "height", 0); Integer width = ServletRequestUtils.getIntParameter(request, "width", 0); if (height > 0 || width > 0) { // we are to resize the image file = new File(resourceDir + imageFile.getUrl()); file = imageUtils.resizeImage(file, width, height); } map.put("file", file); return new ModelAndView("fileView", map); }