11.2. The contentType Attribute

The contentType attribute sets the Content-Type response header, indicating the MIME type of the document being sent to the client. For more information on MIME types, see Table 7.1 (Common MIME Types) in Section 7.2 (HTTP 1.1 Response Headers and Their Meaning).

Use of the contentType attribute takes one of the following two forms:

<%@ page contentType="MIME-Type" %>
<%@ page contentType="MIME-Type; charset=Character-Set" %>

For example, the directive

<%@ page contentType="text/plain" %>

has the same effect as the scriptlet

<% response.setContentType("text/plain"); %>

Unlike regular servlets, where the default MIME type is text/plain, the default for JSP pages is text/html (with a default character set of ...

Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.