Java Code Examples for org.springframework.web.servlet.ModelAndView#setViewName()
The following examples show how to use
org.springframework.web.servlet.ModelAndView#setViewName() .
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: ErrorPageRenderController.java From engine with GNU General Public License v3.0 | 6 votes |
@RequestMapping(value = "/{" + ERROR_CODE_PATH_VAR + "}") public ModelAndView render(@PathVariable(ERROR_CODE_PATH_VAR) String code, HttpServletRequest request) { ModelAndView mv = new ModelAndView(); mv.setViewName(errorViewNamePrefix + code + ".ftl"); Exception error = (Exception)request.getAttribute(DefaultExceptionHandler.EXCEPTION_ATTRIBUTE); if (error != null) { StringWriter errorWriter = new StringWriter(); try { error.printStackTrace(new PrintWriter(errorWriter)); } finally { IOUtils.closeQuietly(errorWriter); } mv.addObject(STACK_TRACE_ATTRIBUTE, errorWriter.toString()); } return mv; }
Example 2
Source File: ErrorController.java From Spring-Security-Third-Edition with MIT License | 6 votes |
@ExceptionHandler(Throwable.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ModelAndView exception(final Throwable throwable, final Model model) { logger.error("Exception during execution of SpringSecurity application", throwable); StringBuffer sb = new StringBuffer(); sb.append("Exception during execution of Spring Security application! "); sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error")); if (throwable != null && throwable.getCause() != null) { sb.append("\n\nroot cause: ").append(throwable.getCause()); } model.addAttribute("error", sb.toString()); ModelAndView mav = new ModelAndView(); mav.addObject("error", sb.toString()); mav.setViewName("error"); return mav; }
Example 3
Source File: LoginController.java From Spring-Security-Third-Edition with MIT License | 6 votes |
@GetMapping(value = "/login") public ModelAndView login( @RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false) String logout) { logger.info("******login(error): {} ***************************************", error); logger.info("******login(logout): {} ***************************************", logout); ModelAndView model = new ModelAndView(); if (error != null) { model.addObject("error", "Invalid username and password!"); } if (logout != null) { model.addObject("message", "You've been logged out successfully."); } model.setViewName("login"); return model; }
Example 4
Source File: TrendingRecController.java From Hybrid-Music-Recommender-System with MIT License | 5 votes |
@RequestMapping(value = "trendingRecFrameLoad.do",method = { RequestMethod.GET }) public ModelAndView trendingRecFrameLoad(HttpServletRequest request) { ModelAndView modelAndView=new ModelAndView(); modelAndView.setViewName("trendingRecFrame"); List<Song> trendingSongList=trendingRecService.getSongWithCollectionFlag(request); modelAndView.addObject("trendingSongList",trendingSongList); modelAndView.addObject("test","Name"); return modelAndView; }
Example 5
Source File: UserInterceptor.java From game-server with MIT License | 5 votes |
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView mav) throws Exception { String userName = (String) (request.getSession()).getAttribute(SessionKey.USER_INFO); if (userName == null) { mav.setViewName("redirect:/login"); } }
Example 6
Source File: LogoutController.java From webcurator with Apache License 2.0 | 5 votes |
@Override protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception { ModelAndView mav = new ModelAndView(); mav.setViewName(Constants.VIEW_LOGOUT); return mav; }
Example 7
Source File: ManageController.java From PhrackCTF-Platform-Personal with Apache License 2.0 | 5 votes |
/** * 后台操作日志查看界面 * * @return * @throws Exception */ @RequestMapping(value="/admin/oplogs",method = {RequestMethod.GET}) public ModelAndView OperationLogs() throws Exception { ModelAndView mv = new ModelAndView("admin/oplogs"); Subject currentUser = SecurityUtils.getSubject(); CommonUtils.setControllerName(request, mv); CommonUtils.setUserInfo(currentUser, userServices, submissionServices,mv); if (CommonUtils.CheckIpBanned(request, bannedIpServices)) { currentUser.logout(); return new ModelAndView("redirect:/showinfo?err=-99"); } List<Operatelog> alllogs = operateLogServices.getAllLogs(); ArrayList<OpLogDisp> displist = new ArrayList<OpLogDisp>(); if (alllogs!=null) { for (Operatelog log:alllogs) { OpLogDisp old = new OpLogDisp(); old.setId(log.getId()); old.setIpaddr(log.getIpaddr()); old.setname(userServices.getUserById(log.getOperatorid()).getUsername()); old.setOperatorid(log.getOperatorid()); old.setOperatefunc(log.getOperatefunc()); old.setOperatetime(log.getOperatetime()); displist.add(old); } } mv.addObject("ops", displist); mv.setViewName("admin/oplogs"); return mv; }
Example 8
Source File: PostController.java From Roothub with GNU Affero General Public License v3.0 | 5 votes |
/** * 帖子详情 */ @RequestMapping(value = "/posts/{postId}", method = RequestMethod.GET) public ModelAndView detail(@PathVariable String postId, HttpServletRequest request, HttpServletResponse response) { ModelAndView mv = new ModelAndView(); PostDTO postDTO = postService.getById(postId); if (postDTO == null) { throw new PostException(PostErrorCodeEnum.NOT_FOUND); } // 浏览量+1 postDTO.setViewCount(postDTO.getViewCount() + 1); postService.updateById(postDTO); PostVO postVO = getDTO2VO().apply(postDTO); Integer pageNumber = 1; String page = request.getParameter("page"); if (StringUtils.notEmpty(page)) { try { pageNumber = Integer.valueOf(page); } catch (NumberFormatException e) { pageNumber = 1; } } // 评论 QueryWrapper<Comment> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("post_id", postDTO.getPostId()); queryWrapper.orderByDesc("create_date"); Page<CommentVO> commentVOPage = commentDTOPage2CommentVOPage(commentService.page(pageNumber, 25, queryWrapper)); // 帖子被收藏的数量 int countByTid = 0; mv.addObject("postVO", postVO); mv.addObject("commentVOPage", commentVOPage); mv.addObject("countByTid", countByTid); mv.setViewName(this.getJspPrefix() + "/detail"); return mv; }
Example 9
Source File: ConsoleMenuController.java From console with Apache License 2.0 | 5 votes |
@RequestMapping("/getConsoleMenuZTree") // (remark="跳转到添加菜单信息时,要选择的菜单树页面获取菜单树") public ModelAndView getConsoleMenuZTree(HttpServletRequest request) { int menuId = 1; List<Map<String, Object>> list = this.getAllConsoleMenu(menuId); String menuJson = JSON.toJSONString(list); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("menuJson", menuJson); modelAndView .setViewName("consolemenu/console_menu_power_list"); return modelAndView; }
Example 10
Source File: HelloController.java From audit4j-demo with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/login", method = RequestMethod.GET) public ModelAndView login(@RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false) String logout) { userService.login("test", "123"); ModelAndView model = new ModelAndView(); if (error != null) { model.addObject("error", "Invalid username and password!"); } if (logout != null) { model.addObject("msg", "You've been logged out successfully."); } model.setViewName("login"); return model; }
Example 11
Source File: AdminDynaReport.java From Spring-MVC-Blueprints with MIT License | 5 votes |
@ExceptionHandler(ReportNotFoundException.class) public ModelAndView handleEmployeeNotFoundException( HttpServletRequest request, Exception ex) { ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("exception", ex); modelAndView.addObject("url", request.getRequestURL()); modelAndView.setViewName("error"); return modelAndView; }
Example 12
Source File: MainController.java From MOOC with MIT License | 5 votes |
@RequestMapping(value = "review") // 查看评论 public ModelAndView review(ModelAndView mav, int courseid) { List<Review> reviews = reviewBiz.select(courseid); mav.addObject("reviews", reviews); mav.setViewName("redirect:coursevideo"); return mav; }
Example 13
Source File: OfficialDataController.java From CardFantasy with BSD 2-Clause "Simplified" License | 5 votes |
@RequestMapping(value = "/Wiki/Stages/{stageId}.shtml") public ModelAndView queryStage(HttpServletRequest request, @PathVariable("stageId") int stageId, HttpServletResponse response) throws IOException { ModelAndView mv = new ModelAndView(); OfficialStage stage = this.officialStore.getStageById(stageId); if (stage == null) { response.setStatus(404); return mv; } mv.setViewName("view-stage"); OfficialStageInfo stageInfo = new OfficialStageInfo(stage, officialStore); mv.addObject("stageInfo", stageInfo); return mv; }
Example 14
Source File: ErrorPageController.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** 404 error page viewer. */ @RequestMapping(value = "/404", method = RequestMethod.GET) public ModelAndView e404(HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView(); mav.setViewName("/error/404"); return mav; }
Example 15
Source File: OfficialDataController.java From CardFantasy with BSD 2-Clause "Simplified" License | 5 votes |
private ModelAndView querySkill(OfficialSkill skill, HttpServletRequest request, HttpServletResponse response) throws IOException { ModelAndView mv = new ModelAndView(); try { OfficialSkill[] skills = null; String skillTypeName = null; if (skill == null) { response.setStatus(404); return mv; } skillTypeName = this.officialStore.getSkillTypeNameFromSkillName(skill.getName()); if (skillTypeName != null) { skills = this.officialStore.getSkillsByType(skillTypeName); } this.logger.info("Skill type: " + skillTypeName); this.userActionRecorder.addAction(new UserAction(new Date(), request.getRemoteAddr(), "View Skill", skillTypeName)); mv.setViewName("view-skill"); List<OfficialSkillInfo> skillInfos = new ArrayList<OfficialSkillInfo>(); for (int i = 0; i < skills.length; ++i) { OfficialSkillInfo skillInfo = OfficialSkillInfo.build(skills[i], officialStore); skillInfos.add(skillInfo); } mv.addObject("skillInfos", skillInfos); mv.addObject("skillType", skillTypeName); } catch (Exception e) { this.logger.error(e); } return mv; }
Example 16
Source File: EmpController.java From EasyEE with MIT License | 4 votes |
/** * 转向显示页面 * * @return */ @RequestMapping("page") public ModelAndView page(ModelAndView mv) { mv.setViewName("main/hr/Emp"); return mv; }
Example 17
Source File: ErpStudentController.java From erp-framework with MIT License | 4 votes |
@RequestMapping(value = "/import", method = RequestMethod.GET) @ResponseBody public ModelAndView exceclImport(ModelAndView modelAndView) { modelAndView.setViewName("/import/import"); return modelAndView; }
Example 18
Source File: SolveStatusController.java From PhrackCTF-Platform-Personal with Apache License 2.0 | 4 votes |
@RequestMapping(value = "/taskstat/{id}",method = {RequestMethod.GET}) public ModelAndView SolveStatus(@PathVariable long id) throws Exception { ModelAndView mv = new ModelAndView("taskstat"); Subject currentUser = SecurityUtils.getSubject(); CommonUtils.setControllerName(request, mv); CommonUtils.setUserInfo(currentUser, userServices, submissionServices,mv); if (CommonUtils.CheckIpBanned(request, bannedIpServices)) { currentUser.logout(); return new ModelAndView("redirect:/showinfo?err=-99"); } Challenges thischall = challengeServices.getChallengeById(id); mv.addObject("taskname", thischall.getTitle()); List<Submissions> allsubs = submissionServices.getAllCorrectSubmitByTaskId(id); ArrayList<SolveStat> sst = new ArrayList<SolveStat>(); long order; order = 1; if (allsubs!=null) { for (Submissions sb:allsubs) { Users passeduser= userServices.getUserById(sb.getUserid()); Countries passcountry = countryServices.getCountryById(passeduser.getCountryid()); if (passeduser.getRole().equals("admin")||!passeduser.getIsenabled()) { continue; } SolveStat ss = new SolveStat(); ss.setorder(order++); ss.setsolvername(passeduser.getUsername()); ss.setsolverid(passeduser.getId()); ss.setcountrycode(passcountry.getCountrycode()); ss.setcountryname(passcountry.getCountryname()); Long submittimes = submissionServices.getsubmitTimesByUserIdAndTaskId(sb.getUserid(), id); System.out.println(submittimes); ss.setsubmits(submittimes); ss.settime(sb.getSubmitTime()); sst.add(ss); } } mv.addObject("passtable", sst); mv.setViewName("taskstat"); return mv; }
Example 19
Source File: ShoppingCartController.java From popular-movie-store with Apache License 2.0 | 4 votes |
/** * @param modelAndView * @param session * @param response * @return */ @GetMapping("/cart/show") public ModelAndView showCart(ModelAndView modelAndView, HttpSession session, HttpServletResponse response) { final String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown"); modelAndView.addObject("hostname", hostname); MovieCart movieCart = (MovieCart) session.getAttribute(SESSION_ATTR_MOVIE_CART); log.info("Showing Cart {}", movieCart); if (movieCart != null) { modelAndView.addObject("movieCart", movieCart); AtomicReference<Double> cartTotal = new AtomicReference<>(0.0); Map<String, Integer> movieItems = movieCart.getMovieItems(); List<MovieCartItem> cartMovies = movieCart.getMovieItems().keySet().stream() .map(movieId -> { Movie movie = movieDBHelper.query(movieId); int quantity = movieItems.get(movieId); double total = quantity * movie.getPrice(); cartTotal.updateAndGet(aDouble -> aDouble + total); log.info("Movie:{} total for {} items is {}", movie, quantity, total); return MovieCartItem.builder() .movie(movie) .quantity(quantity) .total(total) .build(); }) .collect(Collectors.toList()); modelAndView.addObject("cartItems", cartMovies); modelAndView.addObject("cartCount", cartMovies.size()); modelAndView.addObject("cartTotal", "" + DecimalFormat.getCurrencyInstance(Locale.US).format(cartTotal.get())); modelAndView.setViewName("cart"); } else { modelAndView.setViewName("redirect:/"); } return modelAndView; }
Example 20
Source File: ManageHarvestAgentController.java From webcurator with Apache License 2.0 | 4 votes |
private ModelAndView getDefaultModelAndView() { ModelAndView mav = new ModelAndView(); mav.addObject(ManageHarvestAgentCommand.MDL_HARVEST_AGENTS, harvestCoordinator.getHarvestAgents()); mav.setViewName(Constants.VIEW_MNG_AGENTS); return mav; }