HttpServletRequest接口的getSession方法
来源:互联网 发布:js base64转换成file 编辑:程序博客网 时间:2024/05/16 17:38
关于HttpServletRequest接口的getSession方法,在页面提交请求到servlet时,用getSession(false)返回的却是一个session对象而不是null的问题。
getSession有两种方法,一个有参的、一个是无参的。
getSession()与getSession(true)一样,获取request对象关联的session对象,如果没有session,则返回一个新的session。
getSession(false)也是返回一个request对象关联的session对象,但如果没有session,则返回null。
Java EE 5 API中的定义:
HttpSession getSession(boolean create)
- Returns the current
HttpSession
associated with this request or, if there is no current session andcreate
is true, returns a new session. - If
create
isfalse
and the request has no validHttpSession
, this method returnsnull
.
在Jsp页面提交表单到servlet时,在servlet中调用getSession(false)时却返回了一个session,而不是null。
原因是Jsp页面会默认创建session对象,即<@page session="true">,默认是true,如果手动将session设为false,则jsp不会创建session对象,页面也就不可以直接使用session对象。这样提交到servlet,用方法getSession(false)返回的就是null。
- HttpServletRequest接口的getSession方法
- HttpServletRequest接口的getSession方法
- HttpServletRequest接口的getSession方法
- HttpServletRequest下getSession()方法
- HttpServletRequest接口中的getMethod()方法的实现
- HttpServletRequest和HttpServletResponse接口的方法
- HttpServletRequest的常用方法
- HttpServletRequest常用的方法
- HttpServletRequest的方法
- HttpServletRequest常用的方法
- HttpServletRequest常用的方法
- 获取HttpServletRequest的方法
- HttpServletRequest的getParameter方法
- HttpServletRequest接口
- HttpServletRequest接口
- HttpServletRequest接口
- s2sh中getSession()关闭的方法
- getHibernateTemplate()与getSession()方法的区别
- linux-crontab 命令
- 用Ftrace跟踪内核模块
- 一个简单问题的遗传算法的实现
- C#中父窗口和子窗口之间实现控件互操作
- 用getch实现控制
- HttpServletRequest接口的getSession方法
- Ubuntu开启root用户及其它登录问题的解决
- 【WM】Phone Canvas重复创建视图的原因
- Ubuntu 10.04 安装配置手记
- [OE]IIS配置全能空间
- 难受
- C++ 语言特性的性能分析 之 影响性能的因素
- 转一张图,非常形象地说明了OSI七层模型
- [OE]让IIS6.0全面支持asp+php+jsp最新完整版