API解释:
getSession
public HttpSession getSession(boolean create)Returns the current HttpSession associated with this request or 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:
[color=red]true[/color] - to create a new session for this request if necessary;
[color=red]false[/color] - 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
getSession
public HttpSession getSession(boolean create)Returns the current HttpSession associated with this request or 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:
[color=red]true[/color] - to create a new session for this request if necessary;
[color=red]false[/color] - 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
本文解析了getSession方法的功能,它用于获取当前请求的HTTP会话。如果请求中不存在有效的会话并且参数为true,则创建新的会话;若参数为false且没有有效会话,则返回null。在响应提交前调用此方法以确保会话正常维护。
2555

被折叠的 条评论
为什么被折叠?



