JSP Tutorials - Herong's Tutorial Examples - Version 4.03, by Dr. Herong Yang
Response Header Lines of Static Files
This section provides tutorial examples of response header lines of static files like hello.html, dot.gif, and hello.pdf. Content-Type header line is set based on file name extension.
Static files can be served directly by Tomcat server, if you copy the files to \local\apache-tomcat-7.0.32\webapps\ROOT. Tomcat server will set "Content_Type" header line based on the file name extension and the MIME settings of the server configuration.
Let's use my test program, HttpRequestGet.java, provided in the previous section to look at response header lines returned by Tomcat 7 server for 3 commonly used file name extensions.
1. Response header lines when requesting .html files:
C:\>java HttpRequestGet /hello.html 8080 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Accept-Ranges: bytes ETag: W/"38-1047470754000" Last-Modified: 12:05:54 GMT Content-Type: text/html Content-Length: 38 Date: 01:43:40 GMT Connection: close <html><body>Hello world!</body></html>
Couple of interesting notes here:
2. Response header lines when requesting .gif files:
C:\>java HttpRequestGet /dot.gif 8080 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Accept-Ranges: bytes ETag: W/"43-1292039810000" Last-Modified: 03:56:50 GMT Content-Type: image/gif Content-Length: 43 Date: 01:48:41 GMT Connection: close GIF89a......
As you can see, Content_Type was set correctly to "image/gif" for file name extension "gif", as defined in the MIME settings. I could not included the entire entity body here because it contains binary data.
3. Response header lines when requesting .pdf files:
C:\>java HttpRequestGet /hello.pdf 8080 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Accept-Ranges: bytes ETag: W/"909-1059333732000" Last-Modified: 19:22:12 GMT Content-Type: application/pdf Content-Length: 909 Date: 01:51:02 GMT Connection: close %PDF-1.3 % ... 4 0 obj ......
Again, Content_Type was set correctly to "application/pdf" for file name extension "pdf", as defined in the MIME settings. I truncated the entity body to save some space.
Last update: 2012.
Table of Contents
JSP (JavaServer Pages) Overview
Tomcat 7 Installation on Windows Systems
Syntax of JSP Pages and JSP Documents
JavaBean Objects and "useBean" Action Elements
►Managing HTTP Response Header Lines
Controlling Response Header Lines
►Response Header Lines of Static Files
Response Header Lines Controlled by "page" Directive
Response Header Lines Controlled by response Object
Accessing File System from JSP Pages
Returning non-HTML Response Body
Returning Attachments for Web Download
Non-ASCII Characters Support in JSP Pages
Overview of JSTL (JSP Standard Tag Libraries)