Multiple choice technology programming languages

Which codeline must be set before any of the lines that use the PrintWriter

  1. setContentWriter()

  2. setWriter()

  3. setPrintType()

  4. setContentType()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

setContentType() must be called before using PrintWriter to inform the browser about the content type (MIME type) and character encoding of the response. Without setting the content type first, the PrintWriter's output may not be correctly interpreted by the client. This is typically done via response.setContentType() before response.getWriter().