Setting content type

I am using servlet to display an Excel file to the browser.hence,for the same I need to set the content type.
I make an object of file by:
File file = new File("abc.xls");
response.setContentType(application.getMimeType(file.getName()))which is giving the output as a garbled value.That is,it is not able to set the content type.
but when I am using
response.setContentType("application/vnd.ms-excel");It sets the content type.
Any idea what is wrong with the first syntax?????//

I think what you wrote and what I wrote is same.
anyhow,the problem got solved using:
response.setContentType(application.getMimeType(file.getName()));I added the following in web.xml
<mime-mapping>
  <extension>xls</extension>
  <mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>

Similar Messages

  • How to set content type while sending an email?

    Hello,
    I want to set content type text/html while send an email using org.apache.commons.httpclient api. I am using MultipartPostMethod method. and i am set using object of multipartpostmethod like post.
    and post.setRequestHeader("Content-Type","text/html").
    but it wont work.
    so please give me a proper solution.
    example::
    MultipartPostMethod post = new MultipartPostMethod("url");
    post.addParameter("msgbody","html message");
    post.setRequestHeader("Content-Type","text/html");
    Regards,
    Bhavesh Kharwa

    Actually, I'm writing a "HashMap" from servlet to applet. I have used your suggested content type "application/octet-stream" and another "appication/x-java-serialized-object" to try it. But in applet side, when I use (HashMap)in.readObject(), it always gives me a exception as:"java.util.HashMap; IllegalAccessException". Why?
    Thankd.

  • I download itext  for convert jsp to PDF. How to set content type for PDF.

    I download itext for convert jsp to PDF. How to set content type for PDF. I try
    <%@ page contentType = "application/pdf;charset=TIS-620" %>
    , but the page does not PDF.
    Thank.

    PDF files are usually binary files, JSPs are not well-suited for binary content.
    (If you download the result of your JSP you'll see that it is not a valid PDF file; it will have probably a lot of whitespace and linefeeds, that will choke your PDF reader.). The first few characters must be
    "%PDF-" without whitespace.
    You can try using PDF files encoded as text - check if you can use text-encoded PDFs in iText.
    Try using a Servlet instead.

  • Set content type in respone

    Hi,
    I am using velocity model and to set the content type of response as csv report i am setting content type of response as
    $response.setContentType("application/vnd.ms-excel")
    This stmt opens up open-save download dialog box. But the problem is a new internet browser window also opens up. I want to hide this newly opened browser till i click on open button.
    How i can hide or disable this IE window.

    Ritu,
    U specified only content type , try to specifiy attributes like attachment where u can rid of the IE explorer.
    if u have any other doubts u r most welcome giving me a mail [email protected]
    Thanks.
    Sravan

  • Document Set Content Type Workflow

    I have a document library in Share Point 2013 that is using Document Sets.  I need to set up a workflow under the document content type that would send an e-mail if documents have not been uploaded by a specific due date in the document set.  Any
    Help will be greatly appreciated.

    Hi,
    Based on your description, my understanding is that you want to send an email if there is no document uploaded to the document set by a specific due date in the document set.
    I recommend to create retention policy on the document set content type in the library to start the workflow at the due date.
    The workflow can be created as the image below:
    Firstly, get the max id in the library for using in the loop condition in the workflow:
    You can follow the link below for details:
    http://social.technet.microsoft.com/Forums/en-US/a8a890b5-f5fb-447f-b96f-9f3abdb7e178/forum-faq-sharepoint-2013-extracting-values-from-a-multivalue-enabled-lookup-column-and-merge?forum=sharepointgeneral
    Secondly, we need to loop through the items in the library and then check if there are documents(including folders)
     existed inside the document set which is called text for example.
    Please change the string “/sites/victoria/lib set/” in the Replace Substring in String step to be the relative URL of your library and make sure that there is a space before the document set name in the if condition in the workflow as the image below shows:
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Urgent: How to set content type on upload depending on target folder?

    Hi,
    i have to set the content type of a file uploaded via SMB depending on the folder the file is placed in. All files placed below a certain root directory have to be of my custom content type. All others should be stored as documents of type "Document". Is there an easy way to accomplish this task? I can't assume any specific file extensions and can therefore not register my custom content type to that extension.
    Any hints are welcome.
    Thanks.

    Hi,
    i have to set the content type of a file uploaded via SMB depending on the folder the file is placed in.All files placed below a certain root directory have to be of my custom content type.
    +++ Use an agent to verify the name and extension using the IfsEvent class and EVENTTYPE_CREATEINSTANCE
    All others should be stored as documents of type "Document". Is there an easy way to accomplish this task?
    +++ Those that aren't your custom content type move to a different folder using the agent.
    I can't assume any specific file extensions and can therefore not register my custom content type to that extension.
    +++I've found that registering content type only really affects things like how a browser knows what kind of file it's downloading/looking at (mime type) or how a renderer knows how to render it.
    Any hints are welcome.
    Thanks.

  • How to set content type for a JSF page

    Hi,
    I want to know is there any way we can specify the content type of a JSF page, like in JSPs we have the page attribute <%@ page contentType="application/vnd.ms-excel" %>
    In JSP we can create a html table with values and if we specify the contenType as application/vnd.ms-excel, we would get an excel file generated.
    But do we have something similar to this is JSF, as I am using Facelets I cannot use page directive in the xhtml file.
    I tried setting the content type in MangedBean's action as follows
    ((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).setContentType("application/vnd.ms-excel"); but it did'nt work.
    Thanks in advance.

    //add related mutip-part to combine parts
    MimeMultipart multipart = new MimeMultipart("related");
    //attach a pdf
    messageBodyPart = new MimeBodyPart();
    fds = new FileDataSource("h:/something.pdf");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.setFileName(fds.getName());
    multipart.addBodyPart(messageBodyPart);
    //add multipart to the message
    message.setContent(multipart);
    //send message
    Transport.send(message);

  • How to set content type in servlet?

    Hi, there,
    I'm writing a servlet to use ObjectOutputStream to return an object to applet. How can I set this content type in servlet?
    Thanks.

    Actually, I'm writing a "HashMap" from servlet to applet. I have used your suggested content type "application/octet-stream" and another "appication/x-java-serialized-object" to try it. But in applet side, when I use (HashMap)in.readObject(), it always gives me a exception as:"java.util.HashMap; IllegalAccessException". Why?
    Thankd.

  • How to set content-type for outbound mail in BCS

    Hey everybody,
    can anybody please give me a hint how to set the content-type for outbound email in ABAP using BCS to send mail.
    By default the content tyoe is set to text/html. I need other.
    Best regards
    Roman

    //add related mutip-part to combine parts
    MimeMultipart multipart = new MimeMultipart("related");
    //attach a pdf
    messageBodyPart = new MimeBodyPart();
    fds = new FileDataSource("h:/something.pdf");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.setFileName(fds.getName());
    multipart.addBodyPart(messageBodyPart);
    //add multipart to the message
    message.setContent(multipart);
    //send message
    Transport.send(message);

  • How to set content type in SOAP AXIS sender adapter

    Hi All,
    I am trying to fetch the data from an URL which has special characters(like Ä, ï) using SAP PI - SOAP AXIS adapter. I am facing the below error in the channel.
    “error during receive: java.io.UnsupportedEncodingException: charset: utf-8”
    I need to set the content type as ISO-9958-1 but there is no such option present in the SOAP AXIS sender Adapter. Please let me know if there is any way to set the content type and fetch the data successfully.
    Thanks,
    Konda

    Hi Sudha,
    I have tried textcodepageconversion, Message
    Transformation and Annomizer beans but didn't help and this error is in sender SOAP AXIS adapter.
    Thanks,
    Konda

  • How to set content type for the attachment?

    Hello Everybody,
    I was trying to do the following in my send mail program:-
    1. I am making a file using FileWriter:
    FileWriter fw = new FileWriter(f);
    fw.write(str);
    2. I now want to attach this file with my mail. but before that I want to set the Content type of this as "application/smil". and trying the following code:
    mimebodyparts[0].setContent(fds[0],"application/smil");
    As this is a new MIME type perhaps I need to change the mailcap file. I found the same in the activation jar package but thought instead of chagning the default file i tried putting following code in my program:
                  File capfile = new File("simple.mailcap");
                  if (!capfile.isFile())
                        System.out.println("Cannot locate the \"simple.mailcap\" file.");
                        System.exit(1);
                  CommandMap.setDefaultCommandMap( new MailcapCommandMap(new FileInputStream(capfile)));
    and in simple.mailcap file put the following value
    application/smil;;     x-java-content-handler=com.sun.mail.handlers.application_smil  but I am still getting the following error:
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/smil
    Can somebody Please help to sort this out.
    regards,
    Arun

    //add related mutip-part to combine parts
    MimeMultipart multipart = new MimeMultipart("related");
    //attach a pdf
    messageBodyPart = new MimeBodyPart();
    fds = new FileDataSource("h:/something.pdf");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.setFileName(fds.getName());
    multipart.addBodyPart(messageBodyPart);
    //add multipart to the message
    message.setContent(multipart);
    //send message
    Transport.send(message);

  • How to set Content-Type of attachment?

    Does anyone know how I can set the Content-Type of an attachment of an outgoing mail?
    I use Apple Mail, and with one correspondent I have this annoying problem that he never receives any excel or word attachments that I send (and possibly other ones, too).
    Our support now says that I should try to set the Content-Type
    of the excel attachments to "Content-Type: application/vnd.ms-excel".
    Apple Mail seems to set it to
    "Content-Type: application/octet-stream"
    and they think that attachments with this content-type might get blocked by the mail server of my correspondent.
    Any suggestions, ideas, etc., will be appreciated.
    Best regards,
    Gabriel.

    Thanks a lot for your test.
    Unfortunately, I get
    Content-Type: application/octet-stream;
    when I try to send an excel attachment to myself.
    Below is the beginning of the email (in "source" format).
    Any ideas why you get the correct mime-type, but I don't?
    Regards,
    Gabriel.
    ---------- beginning of email
    Return-Path: <[email protected]>
    Received: from [80.128.100.143] (account xxxxxxx HELO [192.168.2.100])
    by tu-clausthal.de (CommuniGate Pro SMTP 5.2.4)
    with ESMTPSA id 35503032 for [email protected]; Mon, 30 Jun 2008 21:59:05 +0200
    Message-Id: <[email protected]>
    From: Gabriel Zachmann <[email protected]>
    To: Gabriel Zachmann <[email protected]>
    Content-Type: multipart/signed; boundary=Apple-Mail-13-325543015; micalg=sha1; protocol="application/pkcs7-signature"
    Mime-Version: 1.0 (Apple Message framework v924)
    Subject: test
    Date: Mon, 30 Jun 2008 21:59:04 +0200
    X-Mailer: Apple Mail (2.924)
    --Apple-Mail-13-325543015
    Content-Type: multipart/mixed;
    boundary=Apple-Mail-12-325542957
    --Apple-Mail-12-325542957
    Content-Disposition: attachment;
    filename="Kostenabfrage AVILUS Gesamtinklusive_TPxyz 080606.xls"
    Content-Type: application/octet-stream;
    x-mac-creator=5843454C;
    x-unix-mode=0644;
    x-mac-type=584C5338;
    name="Gesamt.xls"
    Content-Transfer-Encoding: base64

  • Setting Content-Type in .jspx file

    Hello,
    My application is not rendered by an HTML Browser.
    I need to set the contentType to application/x-ywidget+xml in my JSPX file.
    The content type returned is always text/xml !!!
    I have tried:
    1. To create a phaseListener and overloading before or after phase in ANY_PHASE
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext extContext = context.getExternalContext();
    HttpServletResponse response =
    (HttpServletResponse)extContext.getResponse();
    String contentType = "application/x-ywidget+xml";
    response.setContentType(contentType);
    2. To add a new MimeType extension in web.xml and create my file under this extension
    <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.xygo</url-pattern>
    </servlet-mapping>
    <mime-mapping>
    <extension>xygo</extension>
    <mime-type>application/x-ywidget+xml</mime-type>
    </mime-mapping>

    Frank,
    Thanks you for you help.
    What i would like to do is to use a JSF library components to build YahooGO pages (Yahoo mobile widgets).
    For this my server needs to return an xml document with the application/x-ywidget+xml content type.
    Regarding you question i don't think that the target device understand the HTML.. on my mobile, it's J2ME application...
    Perhaps you can provide me some advices.
    Regards,
    Fred

  • Setting Content-Type when posting a SOAPMessage

    Hi,
    I have to change the Content-Type header before I send the SOAPMessage. But when I try to do that with code similar to the one below, the old header is used anyway. Any solution?
    SOAPMessage msg = createSOAPMessage();
    MimeHeaders headers = msg.getMimeHeaders();
    headers.setHeader("Content-Type", headers.getHeader("Content-Type")[0] + additionalParameters);
    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection con = scf.createConnection();
    SOAPMessage reply = con.call(msg, "http://localhost:8080");

    I've found that when calling the saveChanges() method on a SOAPMessage instance that doesn't have any attachments, the 'Content-Type' header is set to 'text/xml; charset="utf-8"'. So what you should do is that you should be sure to set the 'Content-Type' header after any possible changes to the message have been saved.
    SOAPMessage msg = createSOAPMessage();// Modify message by adding elements...
    // Save the changes made to the message and then
    // change the "Content-Type" header...
    if (msg.saveRequired()) {
    msg.saveChanges();
    MimeHeaders headers = msg.getMimeHeaders();
    headers.setHeader("Content-Type",
    headers.getHeader("Content-Type")[0] +
    additionalParameters);
    SOAPConnectionFactory scf =
    SOAPConnectionFactory.newInstance();
    SOAPConnection con = scf.createConnection();
    SOAPMessage reply = con.call(msg,
    "http://localhost:8080");
    Hope this helps!
    BR
    Daniel

  • Set content type on header doesn't work on servlet filter

    I am trying the following filter:
    chain.doFilter(req, responseWrapper);
    and im trying to set the content type:
    response.SetHeader("Content-Type","text/plain");
    But it doesn't seem to set it.
    I have the wrapper as:
    private ByteArrayOutputStream     output;
         private int                              contentLength;
         private String                         contentType;
         private CharArrayWriter               myOut;
         private int                              mode;
         public JPServletResponseWrapper(HttpServletResponse response) {
              super(response);
              output = new ByteArrayOutputStream();
              this.myOut = new CharArrayWriter();
         public ServletOutputStream getOutputStream() throws IOException {
              this.setMode(2);
              return new JPServletOutputStream(output);
         public PrintWriter getWriter() throws IOException {
              this.setMode(1);
              return new PrintWriter(this.myOut);
         public byte[] getData() {
              return output.toByteArray();
         public int getContentLenght() {
              return this.contentLength;
         public void setContentLength(int len) {
              this.contentLength = len;
              super.setContentLength(len);
         public String getContentType() {
              return this.contentType;
         public void setContentType(String type) {
              this.contentType = type;
              super.setContentType(type);
         public int getMode() {
              return mode;
         public void setMode(int mode) {
              this.mode = mode;
         public String toString() {
              return myOut.toString();
    The page is being displayed as text/html and not as text/plain.
    Is there any reason?

    Hello,
    I think RowOrdinal is the problem. You can try below suggestion:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/634b3f24-b009-415d-8b45-40c11105b803/bug-in-creating-more-columns-in-sharepoint-list-filters?forum=sharepointdevelopmentlegacy
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

Maybe you are looking for

  • Audio scrubbing problem in Soundtrack Pro

    Hi, new to this forum but not new to pro audio! I've been all round the houses trying to fix this one; hope somebody knows the answer. The problem is that although FCP's audio works as expected through the AJA, Soundtrack Pro only outputs playback au

  • Trace file issue...

    Hi All, When I start the database it contineuos write the trace file without any reason.. These are more information on this -rw-r----- 1 oracle dba 95433 Oct 18 12:49 owsidev_reco_1273966.trc -rw-r--r-- 1 oracle dba 302216 Oct 18 12:49 alert_OWSIDEV

  • Possible to add a CS4 SubForum @Photoshop?

    http://www.adobeforums.com/webx/.ee6b366/ Would it be possible to re-structure the Photoshop forum, to add a SubForum for CS4 questions? Such as... Ask CS4 Questions Here

  • G++  library problem after osx maverick upgrade.

    I have upgrade my os x from lion to os x 10.9.1   but when I try to compile my .cpp file like >g++ exe1.cpp -o exe1 I receive following error for libaray files. map.cpp:2:20: error: string.h: No such file or directory map.cpp:3:20: error: iostream: N

  • Hr Infotyp 552. FM - how to get the  Year Month Day?

    Hello In Infoty 552 you find a table with the dateelements  DURYY, DURMM, DURDD. But all field values are 0 when i look at the table with se16n. When i look at the infotyp with pa20, i see the right values - so they must be calculated at run time. Do