请教servlet中getsession的用法
HttpSessionsession=request.getSession(false);HttpSessionsession=request.getSession(tr...
HttpSession session = request.getSession(false);
HttpSession session = request.getSession(true);
HttpSession session = request.getSession();
这三种分别什么意思 展开
HttpSession session = request.getSession(true);
HttpSession session = request.getSession();
这三种分别什么意思 展开
3个回答
展开全部
getSession是返回当前用户的会话对象,参数的区别在于
参数为true,则如果“当前用户的会话对象”为空(第一次访问时)则创建一个新的会话对象返回
参数为false,则如果“当前用户的会话对象”为空,则返回null(即不自动创建会话对象)
注意request.getSession() 等同于 request.getSession(true),除非我们确认session一定存在或者sesson不存在时明确有创建session的需要,否则请尽量使用request.getSession(false)。
参数为true,则如果“当前用户的会话对象”为空(第一次访问时)则创建一个新的会话对象返回
参数为false,则如果“当前用户的会话对象”为空,则返回null(即不自动创建会话对象)
注意request.getSession() 等同于 request.getSession(true),除非我们确认session一定存在或者sesson不存在时明确有创建session的需要,否则请尽量使用request.getSession(false)。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
See Also:
getSession()
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
See Also:
getSession()
参考资料: J2EE-API
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去看看文档好了!那是官方的。应该是最准确的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询