翻译过来的意思就是:getSession(boolean create)是返回当前reqeust中的HttpSession ,如果当前reqeust中的HttpSession为null,当create为true,就创建一个新的Session;当create为false,则返回null。create的默认值为true,即这里的HttpServletRequest.getSession(ture)等同于HttpServletRequest.getSession()。 根据这个特性,在使用上,当向Session中存取登录信息时,一般建议使用request.getSession()/request.getSession(true);当从Session中只获取登录信息时,一般建议使用request.getSession(false)。 当然了,现在各种Web框架都会封装一些方便存取Session的工具类,一般是不建议直接从request中获取Session或前台参数什么的。 "不要轻易把伤口揭开给别人看,因为别人看的是热闹,而痛的却是自己。" |
|