GSNA · Question #275
You work as a Software Developer for UcTech Inc. You want to create a new session. Which of the following methods can you use to accomplish the task?
The correct answer is C. getSession() D. getSession(true). The getSession() method of the HttpServletRequest interface returns the current session associated with the request, or creates a new session if no session exists. The method has two syntaxes as follows: public HttpSession getSession(): This method creates a new session if it…
Question
You work as a Software Developer for UcTech Inc. You want to create a new session. Which of the following methods can you use to accomplish the task?
Options
- AgetNewSession(true)
- BgetSession(false)
- CgetSession()
- DgetSession(true)
- EgetNewSession()
How the community answered
(41 responses)- A7% (3)
- B17% (7)
- C73% (30)
- E2% (1)
Explanation
The getSession() method of the HttpServletRequest interface returns the current session associated with the request, or creates a new session if no session exists. The method has two syntaxes as follows: public HttpSession getSession(): This method creates a new session if it does not exist. public HttpSession getSession(boolean create): This method becomes similar to the above method if create is true, and returns the current session if create is false. It returns null if no session exists. Answer: B is incorrect. The getSession(false) method returns a pre-existing session. It returns null if the client has no session associated with it.
Topics
Community Discussion
No community discussion yet for this question.