I presumed the HTML forum would be best suited for this question.
Right now I'm creating a server/client setup in Java for a school project, and outside of the school work I'm implementing some other things too, just for the fun of it, and to learn. I added a second server class to handle HTTP requests, from a normal browser. The HTTPServer class sends back a html page, which also has some images in it. Now to my question
When the browser gets an <img> tag with a 'src', how does it fetch the image? Do the browser send a new request (for every image) that the server handles seperately or is the image somehow sent together with the first response from the server? I got it working, displaying an image on the page, but I ran two Java server classes at the same time. One for the actual page and one for the image, listening on different ports.
Hmm, I now realized my question is more of a Java question than HTML... Perhaps someone can help any way?
In short. In Java, can I somehow do like this:
Code:
/**
* println(OutputStream os, String str) is a method for sending strings to
* the connected client (browser) and jpeg is a byte[] array with the image.
* write(byte[] b) is used to send bytes via the OutputStream
*/
println(os, "My image: ");
println(os, "<img src=\"");
os.write(jpeg);
println(os, "\">");
Or do I have to do this
Code:
println(os, "My image: ");
println(os, "<img src=\"my_address/get_image\">");
and then interpret the 'get_image' request to respind with an image?
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
|