Java Code Examples for org.springframework.web.servlet.ModelAndView#setViewName()

The following examples show how to use org.springframework.web.servlet.ModelAndView#setViewName() . These examples are extracted from open source projects. 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
@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 2
@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
@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 4
/**
 * 帖子详情
 */
@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 5
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 6
Source Project: kafka-eagle   File: ErrorPageController.java    License: Apache License 2.0 5 votes vote down vote up
/** 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 7
@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 8
Source Project: MOOC   File: MainController.java    License: MIT License 5 votes vote down vote up
@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 9
Source Project: Spring-MVC-Blueprints   File: AdminDynaReport.java    License: MIT License 5 votes vote down vote up
@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 10
Source Project: audit4j-demo   File: HelloController.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: console   File: ConsoleMenuController.java    License: Apache License 2.0 5 votes vote down vote up
@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 12
@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 13
/**
 * 后台操作日志查看界面
 * 
 * @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 14
Source Project: webcurator   File: LogoutController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
       ModelAndView mav = new ModelAndView();
       mav.setViewName(Constants.VIEW_LOGOUT);

       return mav;
}
 
Example 15
Source Project: game-server   File: UserInterceptor.java    License: MIT License 5 votes vote down vote up
@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 16
Source Project: EasyEE   File: EmpController.java    License: MIT License 4 votes vote down vote up
/**
 * 转向显示页面
 * 
 * @return
 */
@RequestMapping("page")
public ModelAndView page(ModelAndView mv) {
	mv.setViewName("main/hr/Emp");
	return mv;
}
 
Example 17
Source Project: erp-framework   File: ErpStudentController.java    License: MIT License 4 votes vote down vote up
@RequestMapping(value = "/import", method = RequestMethod.GET)
@ResponseBody
public ModelAndView exceclImport(ModelAndView modelAndView) {
    modelAndView.setViewName("/import/import");
    return modelAndView;
}
 
Example 18
@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
/**
 * @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
private ModelAndView getDefaultModelAndView() {
	ModelAndView mav = new ModelAndView();
       mav.addObject(ManageHarvestAgentCommand.MDL_HARVEST_AGENTS, harvestCoordinator.getHarvestAgents());
       mav.setViewName(Constants.VIEW_MNG_AGENTS);
	return mav;
}