I\'m working on my first homework project in a web programming class, which is to write a simple web server in Java. I\'m at the point where I have data being transmitted back a
The problem you are seeing is most likely related to a missing flush()
on your writer
. Depending on which type of Writer
you use the bytes are first written to a buffer that needs to be flushed to the stream. This would explain why Content-Length
and Content-Type
are missing in the output. Just flush it before you write additional data to the stream.
Further you call sendFile("/404.html", sock);
. You did not post the full method here - but I suppose that you call it recursively inside sendFile
and thus send the 200 OK
status for your file /404.html
.