Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp The contentType Attribute of page Directive In JSP

Related Tutorials


 
 

Share on Google+Share on Google+

The contentType Attribute of page Directive In JSP

Advertisement
This section gives you the best illustration about the contentType attribute of the page directive in JSP.

The contentType Attribute of page Directive In JSP

     

This section gives you the best illustration about the contentType attribute of the page directive in JSP. This attribute specifies the MIME type and the character encoding i.e. used for the JSP response. The default MIME type is "text/html" and the default character set is "ISO-8859-1". You can also specify other.

In this section, two JSP files have been provided for showing different result after setting the different values of the contentType attribute of the page directive in JSP. Here, the value of the attribute in the ContentTypeAttribute1.jsp is "text/html". So, the page shows a table in the html format while the value of the attribute in the ContentTypeAttribute2.jsp is "text/xml". So, the ContentTypeAttribute2.jsp shows the complete html code of the jsp file in the xml format.

Here is the JSP code of ContentTypeAttribute1.jsp file:

<%@page contentType="text/html" %>
     <html>
	<head><title>Example of contextType attribute of page directive in JSP.</title></head>
		<body>
		<table border="1" cellspacing="0" cellpadding="0" bgcolor="ffff00">
			<tr>
				<td><strong>This is the html page.</strong></td>
			</tr>
		</table>
	</body>
</html>

Output of the ContentTypeAttribute1.jsp file:

Here is the JSP code of ContentTypeAttribute2.jsp file:

<%@page contentType="text/xml" %>
      <html>
      <head><title>Example of contextType attribute 
of page directive in JSP.</title></head>
      <body>
  <table border="1" cellspacing="0" cellpadding="0" bgcolor="ffff00">
 <tr>
	<td><strong>This is the xml page.</strong></td>
 </tr>
	</table>
</body>
</html>

Output of the ContentTypeAttribute2.jsp file:

Download ContentTypeAttribute1.jsp.

Download ContentTypeAttribute2.jsp.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 6, 2008

Related Tutorials

Discuss: The contentType Attribute of page Directive In JSP   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Hamid
January 17, 2013
Thank you

I really find your postings useful. They're short and informative. Thanks, H
DMCA.com