# What is contentType attribute in JSP?

JSPJava 8Object Oriented ProgrammingProgramming

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" %>

Published on 20-Mar-2019 07:52:06