Java Code Examples for org.springframework.web.bind.ServletRequestUtils#getStringParameter()
The following examples show how to use
org.springframework.web.bind.ServletRequestUtils#getStringParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerfController.java From oneops with Apache License 2.0 | 6 votes |
/** * Gets the chart data. * * @param request the request * @param response the response * @return the chart * @throws Exception the exception */ @RequestMapping("/getChart") public void getChart(HttpServletRequest request, HttpServletResponse response) throws Exception { String chartSetJson = ServletRequestUtils.getStringParameter(request, "chartSet"); Chart[] reqs = gson.fromJson(chartSetJson, Chart[].class); long startTime = System.currentTimeMillis(); StringBuilder der = new StringBuilder("["); for (int i = 0; i < reqs.length; i++) { Chart chart = reqs[i]; if (i > 0) { der.append("["); } chart = perfDao.getChart(chart.getKey()); der.append(gson.toJson(chart)); } der.append("]"); long endTime = System.currentTimeMillis(); long duration = endTime - startTime; logger.debug(request.getRemoteAddr() + " took " + duration + " ms"); response.getOutputStream().print(der.toString()); response.setStatus(200); }
Example 2
Source File: SysLogController.java From EasyEE with MIT License | 6 votes |
/** * 分页查询 * * @return * @throws Exception */ @SuppressWarnings("rawtypes") @RequestMapping("list") public Map<Object, Object> list(SysLogCriteria sysLogCriteria) throws Exception { String sort = ServletRequestUtils.getStringParameter(request, "sort", ""); String order = ServletRequestUtils.getStringParameter(request, "order", ""); if (!isNotNullAndEmpty(sort)) { sort = "logTime"; } if (!isNotNullAndEmpty(order)) { order = "desc"; } PageBean pb = super.getPageBean(); // 获得分页对象 pb.setSort(sort); pb.setSortOrder(order); sysLogService.findByPage(pb, sysLogCriteria); return super.setJsonPaginationMap(pb); }
Example 3
Source File: SysLogController.java From EasyEE with MIT License | 6 votes |
/** * 分页查询 * * @return * @throws Exception */ @SuppressWarnings("rawtypes") @RequestMapping("list") public Map<Object, Object> list(SysLogCriteria sysLogCriteria) throws Exception { String sort = ServletRequestUtils.getStringParameter(request, "sort", ""); String order = ServletRequestUtils.getStringParameter(request, "order", ""); if (!isNotNullAndEmpty(sort)) { sort = "logTime"; } if (!isNotNullAndEmpty(order)) { order = "desc"; } PageBean pb = super.getPageBean(); // 获得分页对象 pb.setSort(sort); pb.setSortOrder(order); sysLogService.findByPage(pb, sysLogCriteria); return super.setJsonPaginationMap(pb); }
Example 4
Source File: SmsCodeFilter.java From FEBS-Security with Apache License 2.0 | 6 votes |
private void validateSmsCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException { String smsCodeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "smsCode"); String mobile = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "mobile"); ValidateCode codeInSession = (ValidateCode) sessionStrategy.getAttribute(servletWebRequest, FebsConstant.SESSION_KEY_SMS_CODE + mobile); if (StringUtils.isBlank(smsCodeInRequest)) { throw new ValidateCodeException("验证码不能为空!"); } if (codeInSession == null) { throw new ValidateCodeException("验证码不存在,请重新发送!"); } if (codeInSession.isExpire()) { sessionStrategy.removeAttribute(servletWebRequest, FebsConstant.SESSION_KEY_SMS_CODE + mobile); throw new ValidateCodeException("验证码已过期,请重新发送!"); } if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), smsCodeInRequest)) { throw new ValidateCodeException("验证码不正确!"); } sessionStrategy.removeAttribute(servletWebRequest, FebsConstant.SESSION_KEY_SMS_CODE + mobile); }
Example 5
Source File: ImageCodeFilter.java From FEBS-Security with Apache License 2.0 | 6 votes |
private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException { ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, FebsConstant.SESSION_KEY_IMAGE_CODE); String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "imageCode"); if (StringUtils.isBlank(codeInRequest)) { throw new ValidateCodeException("验证码不能为空!"); } if (codeInSession == null) { throw new ValidateCodeException("验证码不存在,请重新发送!"); } if (codeInSession.isExpire()) { sessionStrategy.removeAttribute(servletWebRequest, FebsConstant.SESSION_KEY_IMAGE_CODE); throw new ValidateCodeException("验证码已过期,请重新发送!"); } if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest)) { throw new ValidateCodeException("验证码不正确!"); } sessionStrategy.removeAttribute(servletWebRequest, FebsConstant.SESSION_KEY_IMAGE_CODE); }
Example 6
Source File: CourseController.java From TinyMooc with Apache License 2.0 | 6 votes |
@CheckAuthority(name = "回复话题") @RequestMapping("createReply.htm") public ModelAndView createReply(HttpServletRequest req, HttpServletResponse res) { String courseTimeId = ServletRequestUtils.getStringParameter(req, "courseTimeId", ""); String content = ServletRequestUtils.getStringParameter(req, "content", ""); String parentId = ServletRequestUtils.getStringParameter(req, "parentId", ""); User user = (User) req.getSession().getAttribute("user"); Comment comment = new Comment(); comment.setCommentId(UUIDGenerator.randomUUID()); comment.setCommentDate(new Date()); comment.setCommentContent(content); comment.setCommentObject(courseTimeId); comment.setUser(user); comment.setType("课时"); if (!parentId.equals(null)) { comment.setComment(courseService.findById(Comment.class, parentId)); } courseService.save(comment); return new ModelAndView("redirect:lessonPage.htm?childrenId=" + courseTimeId); }
Example 7
Source File: ValidateCodeFilter.java From SpringAll with MIT License | 6 votes |
private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException { ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE); String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "imageCode"); if (StringUtils.isBlank(codeInRequest)) { throw new ValidateCodeException("验证码不能为空!"); } if (codeInSession == null) { throw new ValidateCodeException("验证码不存在!"); } if (codeInSession.isExpire()) { sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE); throw new ValidateCodeException("验证码已过期!"); } if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest)) { throw new ValidateCodeException("验证码不正确!"); } sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE); }
Example 8
Source File: PageListController.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * * @param request * @param response * @param model * @return * @throws java.lang.Exception */ @RequestMapping(value = TgolKeyStore.PAGE_LIST_CONTRACT_URL, method = RequestMethod.GET) @Secured({TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY}) public String displayPageList( HttpServletRequest request, HttpServletResponse response, Model model) throws Exception { String auditId = ServletRequestUtils.getStringParameter(request, TgolKeyStore.AUDIT_ID_KEY); if (auditId == null) { throw new AuditParameterMissingException(); } Audit audit; try { audit = getAuditDataService().read(Long.valueOf(auditId)); } catch (NumberFormatException e) { throw new ForbiddenPageException(e); } if (isUserAllowedToDisplayResult(audit)) { return pageLinkDispatcher(request, audit, model); } else { // this block can never be reached. the "isUserAllowedToDisplayResult" // method returns true or throws an exception return TgolKeyStore.ACCESS_DENIED_VIEW_NAME; } }
Example 9
Source File: TeamController.java From TinyMooc with Apache License 2.0 | 6 votes |
@RequestMapping("updateDiscuss.htm") public ModelAndView updateDiscuss(HttpServletRequest req, HttpServletResponse res) { String discussId = ServletRequestUtils.getStringParameter(req, "discussId", ""); String topic = ServletRequestUtils.getStringParameter(req, "topic", ""); String content = ServletRequestUtils.getStringParameter(req, "content", ""); Discuss discuss = teamService.findById(Discuss.class, discussId); discuss.setTopic(topic); teamService.update(discuss); DetachedCriteria criteria = DetachedCriteria.forClass(ImageText.class) .createCriteria("resource") .add(Restrictions.eq("resourceObject", discussId)); List<ImageText> texts = (List<ImageText>) teamService.queryAllOfCondition(ImageText.class, criteria); ImageText text = texts.get(0); text.setContent(content); teamService.update(text); return new ModelAndView("/common/outSuccess"); }
Example 10
Source File: FavoriteController.java From TinyMooc with Apache License 2.0 | 6 votes |
@RequestMapping("createFavorite.htm") public void createFavorite(HttpServletRequest req, HttpServletResponse res) throws MarsException, IOException { PrintWriter pw = res.getWriter(); User user = (User) req.getSession().getAttribute("user"); if (user == null) { pw.print("login"); } String url = ServletRequestUtils.getStringParameter(req, "url", ""); String courseId = ServletRequestUtils.getStringParameter(req, "courseId", ""); Course course = courseService.findById(Course.class, courseId); Date favoriteDate = new Date(); try { Favorite favorite = new Favorite(); favorite.setUser(user); favorite.setFavoriteId(UUIDGenerator.randomUUID()); favorite.setFavoriteDate(favoriteDate); favorite.setUrl(url); favorite.setCourseName(course.getCourseTitle()); favorite.setCourseId(courseId); favoriteService.save(favorite); pw.print("true"); } catch (Exception e) { pw.print("false"); } pw.close(); }
Example 11
Source File: AdminController.java From TinyMooc with Apache License 2.0 | 5 votes |
@RequestMapping("alterIterm.htm") public ModelAndView alterIterm(HttpServletRequest req, HttpServletResponse res) { String alterKey = ServletRequestUtils.getStringParameter(req, "alterKey", ""); String alterValue = ServletRequestUtils.getStringParameter(req, "alterValue", ""); String alterIntro = ServletRequestUtils.getStringParameter(req, "alterIntro", ""); String itermId = ServletRequestUtils.getStringParameter(req, "itermId", ""); DataDic dataDictionary = admin.findById(DataDic.class, itermId); dataDictionary.setDicKey(alterKey); dataDictionary.setDicValue(alterValue); dataDictionary.setIntro(alterIntro); admin.update(dataDictionary); return new ModelAndView("redirect:turnToDictionaryManage.htm"); }
Example 12
Source File: TeamController.java From TinyMooc with Apache License 2.0 | 5 votes |
@RequestMapping("makeEssence.htm") public ModelAndView makeEssence(HttpServletRequest req, HttpServletResponse res) { String discussId = ServletRequestUtils.getStringParameter(req, "discussId", ""); Discuss discuss = teamService.findById(Discuss.class, discussId); discuss.setEssence("精华"); teamService.update(discuss); return new ModelAndView("redirect:discussDetailPage.htm?discussId=" + discussId); }
Example 13
Source File: AdminController.java From TinyMooc with Apache License 2.0 | 5 votes |
@RequestMapping("deletFriendLink.htm") public ModelAndView deletFriendLink(HttpServletRequest req, HttpServletResponse res) { String friendlyLinkId = ServletRequestUtils.getStringParameter(req, "friendlyLinkId", ""); FriendliLink friendLink = admin.findById(FriendliLink.class, friendlyLinkId); admin.delete(friendLink); return new ModelAndView("redirect:turnToFriendLinkManage.htm"); }
Example 14
Source File: TeamController.java From TinyMooc with Apache License 2.0 | 5 votes |
@RequestMapping("cancelEssence.htm") public ModelAndView cancelEssence(HttpServletRequest req, HttpServletResponse res) { String discussId = ServletRequestUtils.getStringParameter(req, "discussId", ""); Discuss discuss = teamService.findById(Discuss.class, discussId); discuss.setEssence(""); teamService.update(discuss); return new ModelAndView("redirect:discussDetailPage.htm?discussId=" + discussId); }
Example 15
Source File: TeamController.java From TinyMooc with Apache License 2.0 | 5 votes |
@RequestMapping("addApplyUser.htm") public ModelAndView addApplyUser(HttpServletRequest req, HttpServletResponse res) { String userTeamId = ServletRequestUtils.getStringParameter(req, "userTeamId", ""); UserTeam userTeam = teamService.findById(UserTeam.class, userTeamId); String teamId = userTeam.getTeam().getTeamId(); userTeam.setUserState("批准"); userTeam.setApproveDate(new Date()); userTeam.setContribution(0); userTeam.setUserPosition("组员"); teamService.update(userTeam); return new ModelAndView("redirect:membersAdminPage.htm?teamId=" + teamId); }
Example 16
Source File: AbstractValidateCodeProcessor.java From imooc-security with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void validate(ServletWebRequest request) { ValidateCodeType processorType = getValidateCodeType(request); String sessionKey = getSessionKey(request); C codeInSession = (C) sessionStrategy.getAttribute(request, sessionKey); String codeInRequest; try { codeInRequest = ServletRequestUtils.getStringParameter(request.getRequest(), processorType.getParamNameOnValidate()); } catch (ServletRequestBindingException e) { throw new ValidateCodeException("获取验证码的值失败"); } if (StringUtils.isBlank(codeInRequest)) { throw new ValidateCodeException(processorType + "验证码的值不能为空"); } if (codeInSession == null) { throw new ValidateCodeException(processorType + "验证码不存在"); } if (codeInSession.isExpired()) { sessionStrategy.removeAttribute(request, sessionKey); throw new ValidateCodeException(processorType + "验证码已过期"); } if (!StringUtils.equals(codeInSession.getCode(), codeInRequest)) { throw new ValidateCodeException(processorType + "验证码不匹配"); } sessionStrategy.removeAttribute(request, sessionKey); }
Example 17
Source File: BaseController.java From EasyEE with MIT License | 5 votes |
/** * 获得分页对象,自动封装客户端提交的分页参数 * * @return */ @SuppressWarnings("rawtypes") public PageBean getPageBean() { PageBean pb = new PageBean(); /* * EasyUI Pagination parameter EasyUI Sort parameter */ int page = ServletRequestUtils.getIntParameter(request, "page", 1); int rows = ServletRequestUtils.getIntParameter(request, "rows", 10); String sort = ServletRequestUtils.getStringParameter(request, "sort", ""); String order = ServletRequestUtils.getStringParameter(request, "order", ""); pb.setPageNo(page); pb.setRowsPerPage(rows); // 分页排序 // 防止SQL注入过滤 sort = StringUtils.filterSQLCondition(sort); // 防止SQL注入过滤 order = StringUtils.filterSQLCondition(order); if (isNotNullAndEmpty(sort)) { pb.setSort(sort); } if (isNotNullAndEmpty(order)) { pb.setSortOrder(order); } return pb; }
Example 18
Source File: ValidateCodeServiceImpl.java From microservices-platform with Apache License 2.0 | 5 votes |
/** * 验证验证码 */ @Override public void validate(HttpServletRequest request) { String deviceId = request.getParameter("deviceId"); if (StringUtils.isBlank(deviceId)) { throw new ValidateCodeException("请在请求参数中携带deviceId参数"); } String code = this.getCode(deviceId); String codeInRequest; try { codeInRequest = ServletRequestUtils.getStringParameter(request, "validCode"); } catch (ServletRequestBindingException e) { throw new ValidateCodeException("获取验证码的值失败"); } if (StringUtils.isBlank(codeInRequest)) { throw new ValidateCodeException("请填写验证码"); } if (code == null) { throw new ValidateCodeException("验证码不存在或已过期"); } if (!StringUtils.equals(code, codeInRequest.toLowerCase())) { throw new ValidateCodeException("验证码不正确"); } this.remove(deviceId); }
Example 19
Source File: TeamController.java From TinyMooc with Apache License 2.0 | 4 votes |
@RequestMapping("membersAdminPage.htm") public ModelAndView membersAdminPage(HttpServletRequest req, HttpServletResponse res) { String teamId = ServletRequestUtils.getStringParameter(req, "teamId", ""); User user = (User) req.getSession().getAttribute("user"); Team team = teamService.findById(Team.class, teamId); DetachedCriteria detachedCriteria = DetachedCriteria.forClass(UserTeam.class) .add(Restrictions.eq("team", team)) .add(Restrictions.eq("userState", "批准")) .addOrder(Order.desc("approveDate")); // 批准的UserTeam List<UserTeam> userTeams = (List<UserTeam>) teamService.queryAllOfCondition(UserTeam.class, detachedCriteria); // 申请中的UserTeam DetachedCriteria detachedCriteria2 = DetachedCriteria.forClass(UserTeam.class) .add(Restrictions.eq("team", team)) .add(Restrictions.eq("userState", "申请中")) .addOrder(Order.desc("applyDate")); List<UserTeam> userTeams2 = (List<UserTeam>) teamService.queryAllOfCondition(UserTeam.class, detachedCriteria2); // 个人UserTeam UserTeam userTeam1 = new UserTeam(); // 组长UserTeam2 UserTeam userTeam2 = new UserTeam(); for (int i = 0; i < userTeams.size(); i++) { if (userTeams.get(i).getUser().getUserId().equals(user.getUserId())) { userTeam1 = userTeams.get(i); } if (userTeams.get(i).getUserPosition().equals("组长")) { userTeam2 = userTeams.get(i); } } // 获取小组成员等级及其称号 DetachedCriteria detachedCriteria3 = DetachedCriteria.forClass(Level.class) .add(Restrictions.eq("type", "小组用户")) .addOrder(Order.asc("lvCondition")); List<Level> teamUserLevels = (List<Level>) teamService.queryAllOfCondition(Level.class, detachedCriteria3); // 组内成员等级 Level level1 = new Level(); // 小组等级 Level level2 = new Level(); for (int j = 0; j < teamUserLevels.size(); j++) { if (j == teamUserLevels.size() - 1) { level1 = teamUserLevels.get(j); break; } if (userTeam1.getContribution() != null) { if (userTeam1.getContribution() < teamUserLevels.get(j).getLvCondition()) { level1 = teamUserLevels.get(j - 1); break; } } } // 获取小组等级及其称号 DetachedCriteria detachedCriteria4 = DetachedCriteria.forClass(Level.class) .add(Restrictions.eq("type", "小组")) .addOrder(Order.asc("lvCondition")); List<Level> teamLevels = (List<Level>) teamService.queryAllOfCondition(Level.class, detachedCriteria4); for (int k = 0; k < teamLevels.size(); k++) { if (k == teamLevels.size() - 1) { level2 = teamLevels.get(k); break; } if (team.getConstruction() < teamLevels.get(k).getLvCondition()) { level2 = teamLevels.get(k - 1); break; } } int memberNum = userTeams.size(); req.setAttribute("userTeams", userTeams); req.setAttribute("userTeams2", userTeams2); req.setAttribute("memberNum", memberNum); req.setAttribute("userTeam1", userTeam1); req.setAttribute("userTeam2", userTeam2); req.setAttribute("level1", level1); req.setAttribute("level2", level2); return new ModelAndView("/team/membersAdmin"); }
Example 20
Source File: TeamController.java From TinyMooc with Apache License 2.0 | 4 votes |
@RequestMapping("discussDetailPage.htm") public ModelAndView discussDetailPage(HttpServletRequest req, HttpServletResponse res) { String discussId = ServletRequestUtils.getStringParameter(req, "discussId", ""); //String userId=ServletRequestUtils.getStringParameter(req, "userId", ""); Discuss discuss = teamService.findById(Discuss.class, discussId); User user = discuss.getUser(); User user2 = (User) req.getSession().getAttribute("user"); DetachedCriteria criteria = DetachedCriteria.forClass(Attention.class) .add(Restrictions.eq("userByUserId", user2)) .add(Restrictions.eq("userByAttentionedUserId", user)); DetachedCriteria criteria2 = DetachedCriteria.forClass(Discuss.class) .addOrder(Order.desc("publishDate")) .createCriteria("team") .add(Restrictions.eq("teamId", discuss.getTeam().getTeamId())); DetachedCriteria criteria3 = DetachedCriteria.forClass(Resource.class) .add(Restrictions.eq("resourceObject", discuss.getDiscussId())); DetachedCriteria criteria4 = DetachedCriteria.forClass(UserCourse.class) .add(Restrictions.eq("userPosition", "创建者")) .createCriteria("user") .add(Restrictions.eq("userId", user.getUserId())); DetachedCriteria criteria5 = DetachedCriteria.forClass(UserTeam.class) .add(Restrictions.eq("userPosition", "组长")) .createCriteria("team") .add(Restrictions.eq("teamId", discuss.getTeam().getTeamId())); // DetachedCriteria criteria6 = DetachedCriteria.forClass(Favorite.class) // .add(Restrictions.eq("user", user2)) // .add(Restrictions.eq("objectId", discuss.getDiscussId())); DetachedCriteria criteria7 = DetachedCriteria.forClass(Comment.class) .add(Restrictions.eq("commentObject", discussId)) .add(Restrictions.isNull("comment")) .addOrder(Order.asc("commentDate")); DetachedCriteria criteria8 = DetachedCriteria.forClass(Comment.class) .add(Restrictions.eq("commentObject", discussId)) .add(Restrictions.isNotNull("comment")) .addOrder(Order.asc("commentDate")); DetachedCriteria criteria9 = DetachedCriteria.forClass(Attention.class) .add(Restrictions.eq("userByUserId", user)); List<Attention> attentions = (List<Attention>) teamService.queryAllOfCondition(Attention.class, criteria); List<Discuss> discusses = (List<Discuss>) teamService.queryAllOfCondition(Discuss.class, criteria2); List<Resource> resources = (List<Resource>) teamService.queryAllOfCondition(Resource.class, criteria3); List<UserCourse> userCourses = (List<UserCourse>) teamService.queryAllOfCondition(UserCourse.class, criteria4); List<UserTeam> userTeams = (List<UserTeam>) teamService.queryAllOfCondition(UserTeam.class, criteria5); // List<Favorite> favorites = (List<Favorite>) teamService.queryAllOfCondition(Favorite.class, criteria6); List<Comment> comments = (List<Comment>) teamService.queryAllOfCondition(Comment.class, criteria7); List<Comment> comments2 = (List<Comment>) teamService.queryAllOfCondition(Comment.class, criteria8); List<Attention> attentions2 = (List<Attention>) teamService.queryAllOfCondition(Attention.class, criteria9); Resource resource = resources.get(0); UserTeam userTeam = userTeams.get(0); int courseNum = userCourses.size(); int fansNum = attentions2.size(); int isAttention = 0; if (!attentions.isEmpty()) { isAttention = 1; } int commentNum = comments.size() + comments2.size(); discuss.setScanNum(discuss.getScanNum() + 1); teamService.update(discuss); req.setAttribute("discuss", discuss); req.setAttribute("fansNum", fansNum); req.setAttribute("isAttention", isAttention); req.setAttribute("discusses", discusses); req.setAttribute("resource", resource); req.setAttribute("courseNum", courseNum); req.setAttribute("userTeam", userTeam); // req.setAttribute("flag", flag); req.setAttribute("comments", comments); req.setAttribute("comments2", comments2); req.setAttribute("commentNum", commentNum); return new ModelAndView("/team/discussDetail"); }