JSP Tutorials - Herong's Tutorial Examples - Version 4.03, by Dr. Herong Yang
Controlling Response Header Lines
This section describes 3 ways to control response header lines in JSP pages: using (page contentType='...') directive element; using response.setContentType() and setContentLength(); and using response.setHeader() methods.
When a JSP page is requested, response header lines will be automatically created by the JSP server. But you can control some header lines in three 3 different ways:
1. Using a directive element to set the entity header line: Content_Type, as shown in the following example:
<jsp:directive.page contentType="text/html"/>
2. Using special methods on the "response" object, as defined by the javax.servlet.ServletResponse interface, to set the entity header lines: Content_Type and Content_Length as shown in the following example:
response.setContentType("text/html"); responee.setContentLength(909);
3. Using generic methods on the "response" object, as defined by the javax.servlet.http.HttpServletResponse interface, to add or set any response header lines as shown in the following example:
response.setHeader("Content_Type", "text/html"); response.setIntHeader("Content_Length", 909); response.setDateHeader("Last-Modified", System.currentTimeMillis()); response.addHeader("Content_Type", "charset=ISO-8859-1");
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)