Java Reference
In-Depth Information
error(out, 500, "Invalid request");
return;
}
physicalPath += e;
} else
physicalPath = addSlash(physicalPath);
}
// if there is no file specified, default
// to index.html
if (physicalPath.endsWith(File.separator))
{
physicalPath = physicalPath + "index.html";
}
// open the file and send it if it exists
File file = new File(physicalPath);
if (file.exists())
{
// send the file
FileInputStream fis = new FileInputStream(file);
byte buffer[] = new byte[(int) file.length()];
fis.read(buffer);
fis.close();
this.transmit(out, 200, "OK", buffer,
getContent(physicalPath));
}
// file does not exist, so send file not found
else
{
this.error(out, 404, "File Not Found");
}
}
/**
* Transmit a HTTP response. All responses are handled by
* this method.
*
* @param out The output stream.
* @param code The response code, i.e. 404 for not found.
* @param message The message, usually OK or error message.
* @param body The data to be transfered.
* @param content The content type.
Search WWH ::




Custom Search