To get an object of PrintWriter, we use getWriter() method of class _____________
-
HttpSession
-
HttpServletResponse
-
HttpServletRequest
-
None
The getWriter() method belongs to HttpServletResponse interface and returns a PrintWriter object for sending character-based response data. HttpServletRequest is for incoming request data, while HttpSession manages user session state.
To get an object of PrintWriter in Java, we use the getWriter() method of the HttpServletResponse class.
Option A) HttpSession - This option is incorrect because the getWriter() method is not a method of the HttpSession class.
Option B) HttpServletResponse - This option is correct. The getWriter() method is a method of the HttpServletResponse class, which is used to send a response to the client.
Option C) HttpServletRequest - This option is incorrect because the getWriter() method is not a method of the HttpServletRequest class.
Option D) None - This option is incorrect because the correct answer is option B, HttpServletResponse.
The correct answer is B) HttpServletResponse. This option is correct because the getWriter() method is used to obtain a PrintWriter object to write the response to the client using the HttpServletResponse class.