您的位置:首页 > Web前端 > JavaScript

(转)jsp页面获取session中值的方式

2019-01-23 17:12 323 查看

jsp页面获取session值

java代码

[code] @RequestMapping(value = "/chkUser",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public String chkUserInfo(HttpServletRequest request,String userName, String userPwd){
        if(StringUtils.isBlank(userName)||StringUtils.isBlank(userPwd))
            return "false";
        UserEntity entity = chkLoginService.chkUserService(userName,userPwd);
        if(entity==null)
            return "false";
        request.getSession().setAttribute("userEntity",entity);
        return "true";
    }

方法一  
jsp页面  
使用  request.getSession().getAttribute(“**“) 方法  

方法二 


在jsp页面 script中使用EL表达式获取  
var userEntity=’${sessionScope.userEntity.loginName}’; 
说明 
1、sessionScope指的是session的范围,类似还有requestScope,pageScope,contextScope 
2、sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值即session.getAttribute(key)

原文:https://blog.csdn.net/xiongdaandxiaomi/article/details/80593244 
 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: