jsp页面获取session中值的方式

您所在的位置:网站首页 java获取session中对象的name值 jsp页面获取session中值的方式

jsp页面获取session中值的方式

2024-06-27 07:56| 来源: 网络整理| 查看: 265

jsp页面获取session值

java代码

@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(“**“) 方法 方法一使用getAttribute

方法二

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3