GSNA · Question #58
Which of the following methods is used to get a cookie from a client? Note: Here, request is a reference of type HttpServletRequest, and response is a reference of type HttpServletResponse.
The correct answer is A. Cookie [] cookies = request.getCookies(). The getCookies() method of the HttpServletRequest interface is used to get the cookies from a client. This method returns an array of cookies. Answer: B, C are incorrect. The getCookie(String str) method does not exist. Answer: D is incorrect. The getCookies() method is present…
Question
Which of the following methods is used to get a cookie from a client? Note: Here, request is a reference of type HttpServletRequest, and response is a reference of type HttpServletResponse.
Options
- ACookie [] cookies = request.getCookies();
- BCookie [] cookies = request.getCookie(String str)
- CCookie [] cookies = response.getCookie(String str)
- DCookie [] cookies = response.getCookies()
How the community answered
(33 responses)- A70% (23)
- B3% (1)
- C9% (3)
- D18% (6)
Explanation
The getCookies() method of the HttpServletRequest interface is used to get the cookies from a client. This method returns an array of cookies. Answer: B, C are incorrect. The getCookie(String str) method does not exist. Answer: D is incorrect. The getCookies() method is present in the HttpServletRequest interface and not in the HttpServletResponse interface.
Topics
Community Discussion
No community discussion yet for this question.