Java Reference
In-Depth Information
* @throws IOException Thrown if any sort of error occurs.
*/
private void transmit(OutputStream out,
int code,
String message,
byte body[],
String content)
throws IOException
{
StringBuilder headers = new StringBuilder();
headers.append("HTTP/1.1 ");
headers.append(code);
headers.append(' ');
headers.append(message);
headers.append("\n");
headers.append("Content-Length: " + body.length + "\n");
headers.append("Server: Heaton Research Example Server\n");
headers.append("Connection: close\n");
headers.append("Content-Type: " + content + "\n");
headers.append("\n");
out.write(headers.toString().getBytes());
out.write(body);
}
/**
* Display an error to the web browser.
*
* @param out The output stream.
* @param code The response code, i.e. 404 for not found.
* @param message The error that occurred.
* @throws IOException Thrown if any sort of error occurs.
*/
private void error(OutputStream out, int code, String message)
throws IOException
{
StringBuilder body = new StringBuilder();
body.append("<html><head><title>");
body.append(code + ":" + message);
body.append(
"</title></head><body><p>An error occurred.</p><h1>");
body.append(code);
body.append("</h1><p>");
body.append(message);
body.append("</p></body></html>");
transmit(out, code, message,
Search WWH ::




Custom Search