2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

How to write bytes in http response

If you need to send bytes, instead of characters as http response, you need to get the Outputstream object using the method OutputStream getOutputStream() of the HttpServletResponse object. Then call the write(Bytes[]) method on it to send the bytes as shown below.

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
	OutputStream out = resp.getOutputStream();
	out.write("It works".getBytes());
}