servlet session

最近项目上出现了一个错误大致代码就是用servletinclude了几个jsp文件,然后session就消失了但在include之前有session则request.ge... 最近项目上出现了一个错误
大致代码就是
用servlet include了几个jsp文件,然后session就消失了
但在include之前有session
则 request.getSession()就出错了
Cannot create a session after the response has been committe
但是这个问题不是每次都出现,只是偶尔出现,在开发环境中也没出现过,在tomcat 中会偶尔出现几次
虽然说只要把request.getSession()改成request.getSession(false)问题就解决了
但是我想知道为什么include之后session就消失了。
看了一会源代码没有找到地方,我用的tomcat 5.5 请比较熟悉原代码的人解释一下
展开
 我来答
匿名用户
2013-09-13
展开全部
看看文档吧
getSession
public HttpSession getSession(boolean create)Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
If create is false and the request has no valid HttpSession, this method returns null.

To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.

Parameters:
true - to create a new session for this request if necessary; false to return null if there's no current session
Returns:
the HttpSession associated with this request or null if create is false and the request has no valid session
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式