request.getSession的用法

HttpRequest对象有两种形式的getSession方法调用,一个是getSession(),另一个是getSession(boolean isNew)这样的,前者会检测当前时候有session存在,如果不存在则创建一个,如果存在就返回当前的。getSession()相当于getSession(false),getSession(true)则不管当前是否存在Session都创建一个。 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
request.getSession().setAttribute()是用来在session对象中设置属性值的方法。通过这个方法,可以将参数存储在session中,并且可以在多个页面上使用。\[3\]这个方法可以通过sessionID得到自己的session,并且即使重定向客户端也不会丢失。\[3\]在引用\[2\]中的例子中,通过request.getSession().setAttribute("name", str)将一个名为"name"的属性赋值为"huxiwen"。然后通过request.getSession().getAttribute("name")可以获取到这个属性的值。\[2\]所以,通过request.getSession().setAttribute()方法可以给session对象设置属性值。 #### 引用[.reference_title] - *1* *2* [对request.getSession().setAttribute和request.getSession().getAttribute()的理解](https://blog.csdn.net/weixin_42200027/article/details/80482716)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [request.setAttribute()和request.getSession().setAttribute()解释](https://blog.csdn.net/sinat_15274667/article/details/51585538)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值