>>> JangHo Ki <[EMAIL PROTECTED]> 22-Apr-00 6:14:33 AM >>>
>hi, guys.
and girls presumably and (fairly obviously) lazy people.
>Usually, web pages consists of combination of texts and
>image files.
That's right. Lesson 1 of the Ladybird book of the web.
>What do I need to specify for setContentType() method in
>this case?
You are confused.
Here is a brief overview of how a webpage gets displayed on your
browser:
- you make a request for, say, http://www.w3c.org/index.html
- the browser constructs and HTTP request like this:
GET /index.html HTTP/1.1
- the browser opens a TCP socket to the host found at: www.w3c.org on
port 80
- the server tries to find the file specified by /index.html (see the
"/index.html" in the request?)
- the server responds to the browser (through the TCP socket)
beginning with the line:
HELLO-DUCKY! HTTP/1.1
Content-Type: text/html
Note: the content type is text/html - why? because that's what is
being sent.
- the server then sends the rest of the HTML file called /index.html
the file might look like this:
<html><head><title>W3C page</title></head>
<body><h1>People keep asking me dumb questions - says Tim Berners
Lee</h1>
<img src="timonhorseback.jpg">
</body>
</html>
Note the image tag.
But remember it's just a tag, it isn't an image.
It's just some text saying what image we would like to see in the
page.
- the browser recieves the HTML page and starts to display it
- as the browser displays the page is notices that there is an IMG
tag
- the browser looks at the SRC tag and constructs an HTTP request for
the file specifed, like this:
GET /timonhorseback.jpg HTTP/1.1
Note: the browser knows that it has to look for the image in the /
directory because that's where the index.html was requested from.
This bit's tricky - pay attention:
- whilst the browser continues to display the rest of the index.html
file it ALSO opens aother TCP connection on port 80 to the server and
sends the request for the image
- the server finds the file associated with /timonhorseback.jpg -
it's a jpeg file so the server responds and sets the content-type like
this:
Content-Type: image/jpeg
- the server sends the rest of the timonhorseback.jpg file over the
TCP socket
- the browser starts recieves the image and uses magic fairy dust to
display it in the browser window
So: to sum up.
When you send content you are only ever sending one kind of content
(the content types are called MIME types).
If you send a page with an image "in it" you are actually just
sending an HTML file with a REFERENCE to an image.
When the browser recieves the page and discovers the REFERENCE it
will ask the server for the image by it's REFERENCE.
Anyone with these sort of questions really ought to try reading the
HTTP/1.1 spec. It's available from the W3C, you can go there by
opening the URL:
http://www.w3c.org
in your browser.
Seriously though... the RFC is very readable and an excellent way of
avoiding sarcastic emails from London hackers.
Nic Ferrier
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html