Spring mvc 设置session和获取值

第一中方式:
@RequestMapping("/index.htm")
	public String index(HttpSession session) {
		session.setAttribute("name", "session");
		Object name = session.getAttribute("name");
		System.out.println(name);
		return "/home";
	}


第二中方式:
@RequestMapping("/index2.htm")
	public String index2(HttpServletRequest request) {
		request.getSession().setAttribute("name", "session");
		Object name = request.getSession().getAttribute("name");
		System.out.println(name);
		return "/home";
	}

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