Generate the output page within a servlet by writing to the output stream. The recommended generation method depends on the output type.
Always specify the output MIME type using setContentType() before any output commences, as follows
response.setContentType("text/html"); |
For textual output, such as plain HTML, create a PrintWriter object and then write to it using println, for example:
PrintWriter output = response.getWriter(); output.println("Hello, World\\n"); |
For binary output, write to the output stream directly by creating a ServletOutputStream object and then write to it using print(), for example:
ServletOutputStream output = response.getOutputStream(); output.print(binary_data); |