Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
252
Chapter 11 The JSP page Directive: Structuring Generated Servlets
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
ISO 8859 1
).
Generating Plain Text Documents
Listing 11.2 shows a document that appears to be HTML but has a
content
Type
of
text/plain
. Strictly speaking, browsers are supposed to display the
raw HTML content in such a case, as shown in Netscape in Figure 11 3.
Internet Explorer, however, interprets the document as though it were of
type
text/html
, as shown in Figure 11 4.
Listing 11.2 ContentType.jsp
The contentType Attribute
The contentType Attribute
<%@ page contentType="text/plain" %>
This should be rendered as plain text,
not as HTML.
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved