What is contentType attribute in JSP?


The contentType attribute sets the character encoding for the JSP page and for the generated response page. The default content type is text/html, which is the standard content type for HTML pages.

If you want to write out XML from your JSP, use the following page directive −

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

The following statement directs the browser to render the generated page as HTML −

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

The following directive sets the content type as a Microsoft Word document −

<%@ page contentType = "application/msword" %>

You can also specify the character encoding for the response. For example, if you wanted to specify that the resulting page that is returned to the browser uses ISO Latin 1, you can use the following page directive −

<%@ page contentType = "text/html:charset=ISO-8859-1" %>

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements