springmvc中将值存入session,jsp页面获取(ps:加获取不去值的坑)

在session中存值:

public ModelAndView loginCkeck(ShopUser shopUser, HttpSession httpSession){
        ModelAndView fail = new ModelAndView("login");
        String username = shopUser.getUsername();
        String password = shopUser.getUpassword();

        List list =userLoginService.login(username,password);
        if( (list != null) &&(list.size()>=1) ){
            httpSession.setAttribute("userInfo",list.get(0));
            return new ModelAndView("redirect:/category");
        }else{
            return fail.addObject("fail","用户名或密码错误");
        }
    }
在前台页面中取值:

			
					
						
  • ${sessionScope.get('userInfo').username}[退出]|
  • 我的订单|
  • 会员登录|
  • 会员注册|


  • 这里有个坑就是在JSTL表达式的前后不能出现空格,否则不会生效

    你可能感兴趣的:(spring)