HttpServletRequest接口的getSession方法
来源:互联网 发布:什么数据比金十数据好 编辑:程序博客网 时间:2024/05/16 12:40
关于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。
原帖地址:http://blog.csdn.net/wing32/article/details/5618106
- 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()方法的区别
- Jpcap的实现过程
- 如何阅读别人的代码---c、c++程序学习
- 用Visual Studio 编译64位程序
- java.lang.IllegalArgumentException: Can't convert argument: null
- vim 使用笔记
- HttpServletRequest接口的getSession方法
- 临时表空间
- MOSS身份安全的初步研究
- [易飞]品号属性的定期监控
- MOSS 权限管理总结
- struts2.0+hibernate+oracle的分页详解
- Android4种布局详解
- 从SQL Server 2008 升级到 SQL Server 2008 R2
- ACM心得——(写的很好,留着警示自己)