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

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

Managing HTTP Response Header Lines

 What Is HTTP Response?

 HTTP Response Header Lines

Controlling Response Header Lines

 Viewing 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

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials

 References

 PDF Printing Version