user2130057
user2130057

Reputation: 406

HTML File not showing images when served through webserver, but if I directly open the html file in the browser it works

I am working on teaching myself a Web Server. My Web server serves html files right now, and that's it. I tried adding an image to the file, and it is not showing up (it's just the empty box with the X). However, if I directly open the html file through my browser it works just fine.

<img src="image.jpg" width = "120" height = "90"/>

*note, this image is in the same folder as the server, hence the filename alone.

The way my web server works is it writes each line, one-by-one from the html file to the browser. Using this method, will the images not function properly? Is there something else I need to do for this to work?

The basic code that is writing the html lines to the browser are as follows:

while ((lines = buffRead.readLine()) != null){

    outStream.write(lines.getBytes());

}

Upvotes: 0

Views: 950

Answers (1)

Kai Mattern
Kai Mattern

Reputation: 3085

There is most probably nothing wrong with the code that write the html line. Well, besides the spaces around the =. You may want to delete them.

However there is simply no image where you say one is, when you use the web server.

You say with that line: Hey browser, try to fetch an image named image.jpg. You will find it right on the same directory level as this html. Go for it.

It then tries and fails. Most probably because there is no such file, or you application does not know how to serve the file.

Have you tried to directly load the image in you browser? Like http://yourhost/image.jpg - or if you are in a sub directory http://yourhost/yourdirectory/image.jpg?

Upvotes: 1

Related Questions