创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
创新互联是一家专业提供义乌企业网站建设,专注与成都网站制作、成都做网站、外贸营销网站建设、HTML5、小程序制作等业务。10年已为义乌众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。这篇文章将为大家详细讲解有关java 中的true、false、null有何不同,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
java 中 request.getSession(true/false/null)的区别
一、需求原因
现实中我们经常会遇到以下3中用法:
HttpSession session = request.getSession();
HttpSession session = request.getSession(true);
HttpSession session = request.getSession(false);
二、区别
1. Servlet官方文档说:
public HttpSessiongetSession(boolean create)
Returns the currentHttpSession associated with this request or, if if there is no current sessionand create is true, returns a new session.
If create is falseand the request has no valid HttpSession, this method returns null.
To make sure thesession is properly maintained, you must call this method before the responseis committed. If the Container is using cookies to maintain session integrityand is asked to create a new session when the response is committed, anIllegalStateException is thrown.
Parameters: true -to create a new session for this request if necessary; false to return null ifthere's no current session
Returns: theHttpSession associated with this request or null if create is false and therequest has no valid session
2. 翻译过来的意思是:
getSession(boolean create)意思是返回当前reqeust中的HttpSession ,如果当前reqeust中的HttpSession 为null,当create为true,就创建一个新的Session,否则返回null;
简而言之:
HttpServletRequest.getSession(ture)等同于 HttpServletRequest.getSession() HttpServletRequest.getSession(false)等同于 如果当前Session没有就为null;
新闻名称:java中的true、false、null有何不同-创新互联
URL链接:http://lswzjz.com/article/ccipde.html