Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
JSP
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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 attribu
te 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.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (post your own) View All Comments Latest 10 Comments:

how we can set the content type to get the result in pdf format.
resp.setContentType("application/pdf");
it should be applicable or not
reply me soon

Posted by shehzad on Friday, 06.15.07 @ 12:24pm | #19297

I want to Send a html file through mail by JSP coding. In that Situation Mail is going but in that mail only display the HTML codings but I want to Send tn HTML format.I included the ContentType="text/html" even though in that mail only displaying the html tags. Could u tel me the solution for that.

Regards
Balamurugan

Posted by Balamurugan on Saturday, 06.2.07 @ 19:21pm | #18032

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.