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



Home Jsp JSP Mime Type

Related Tutorials


 
 

Share on Google+Share on Google+

JSP Mime Type

Advertisement
JSP Mime Type for Multipurpose Internet Mail Extension. MIME is a describe technique for attaching files to Internet mail by changing the raw binary files to printable ASCII.

JSP Mime Type

        

JSP Mime Type for Multipurpose Internet Mail Extension. MIME is a describe technique for attaching files to Internet mail by changing the raw binary files to printable ASCII. It is expanded being used in HTTP describe the content of messages and downloads from to and from servers.

Understand with Example

In this section, you will learn how to get the mime type of the specified file. The mimeType.jsp contain a page import directive that show you the package java.io is imported. You can see in the given example that we have used the class MimetypesFileTypeMap that will map the specified file to a Mime Type. The MimetypesFilesTypeMap extends FileTypeMap provides datatying of files via their file extension. This uses the .mime type format. The method getContentType(file) of this class  return the MIME type based on the specified file name. In the given below example the mime type of file is rose.gif is image/gif.

List of Method used :

MimetypesFileTypeMap().getContentType(file)): This is used to return the MIME type based on the specified file name.

 Here is the code of mimeType.jsp:

<%@ page import="java.io.*"%>
<%@ page import="javax.activation.MimetypesFileTypeMap"%>
<html>
<head>
<title>Get Mime Type</title>
</head>
<%
File file = new File("rose.gif");
out.println("Mime Type of " + file.getName() + " is " +
  new MimetypesFileTypeMap().getContentType(file));
%>
</html>

Output will be displayed as:

Download Source Code:

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 3, 2009

Related Tutorials

Discuss: JSP Mime Type  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com