Spring mvc action调用另一个action

/**
	 * 首页.
	 * 
	 * @return
	 */
	@RequestMapping("/index.htm")
	public String index(HttpSession session) {
		String result = "";
		if (session.getAttribute(Config.Passport.SESSION_NAME_LOGIN_RESULT) != null) {
			result = "/home";
		} else {
			result = "redirect:/login.htm";
		}
		return result;
	}


/**
	 * 登录页.
	 * 
	 * @return
	 */
	@RequestMapping("/login.htm")
	public String login(HttpSession session) {
		return "/login";
	}


// method1
return new ModelAndView("redirect:DummyRedirectPage.htm");

// method2
@RequestMapping({"/someurl"})
public String execute(Model model) {
    if (someCondition) {
        return "forward:/someUrlA";
    } else {
        return "forward:/someUrlB";
    }
}


参考文献:
http://stackoverflow.com/questions/7366170/spring-3-0-forwarding-request-to-different-controller

http://www.mkyong.com/spring-mvc/spring-mvc-redirectview-example/

你可能感兴趣的:(java,spring,mvc,action)