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().