("Content-Disposition", "attachment;filename=x") works in Netscape; not IE.

I'm sending an ASCII file back to the client using the following method:
private void sendFile(String fullFilePath, HttpServletResponse res) {
if(fullFilePath!=null) {
try {
res.setContentType("application/text/plain"); //this will be an unknown type
res.setHeader("Content-Disposition", "attachment;filename=" + fullFilePath);
FileInputStream fi = new FileInputStream(fullFilePath);
OutputStream out = res.getOutputStream();
while(true) {
int d = fi.read();
out.write(d);
if(fi.available()==0)
break;
fi.close();
out.close();
catch (Exception e) {
Logger.err.println("Error in TableQueryServlet.sendFile(): " + e,Log.ERROR);
This works great in Navigator. The filename that it defaults to in the Save file dialog box is the same one I set it to using the fullFilePath string - including the .txt extension. However, in IE it ignores my filename and assigns its own random filename. Any ideas how I can get this to work in IE?

It's not the greatest, but see the following...
MS knowledgebase # Q279667

Similar Messages

  • Download File by url in another server? (Content-Disposition","attachment)

    Can the file be downloaded by a url in another server?
    ie.
    Server A: JSP program
    Server B: filepath + filename = "http://xxx.com/xx/x.doc"
    e.g.
        response.setContentType("APPLICATION/OCTET-STREAM");
           response.setHeader("Content-disposition", "inline" );            
           response.setHeader("Content-Disposition","attachment; filename=\""+ fn.trim() + "\"");     
              java.io.FileInputStream fileInputStream =new java.io.FileInputStream(filepath+filename);
              int i;          
              while ((i=fileInputStream.read()) != -1) {
                      out.write(i);
              fileInputStream.close();
              out.close();     

    I tried this but it doesn't work. In the report column it shows up as Download" >_ .
    This seems to indicate that the href code is not being interpreted correctly.
    Following is exactly what I have in the URL field:
    <a href="#OWNER#.DOWNLOAD_MY_FILE?p_file=#NOTIFICATION_SEQ_ID#&v_type=SUMMARY">Download</a>Yes, I have granted execute rights to the procedure.
    Thanks,
    Dale

  • SetHeader("Content-disposition ) does not work in NN

    response.setHeader("Content-disposition", "attachment; filename="+ fileName + strExt);
    works for IE 5.5 but not in netscape .
    IE 5.5 shows the save as dialog box
    NN4.79 display the contents
    how can i get the save as dialog box in NN4.79

    try adding response.setContentType("your_content_type...") just before calling response.setHeader("Content-disposition", ...).
    It seems that netscape requires it.

  • HTMLLoader & Content-Disposition of type attachment

    HTMLLoader in Adobe AIR 1.0 does not handle the HTTP
    Content-Disposition response headers set to type 'attachment'. It
    simply ignores this header. This is bad, because many sites on the
    web rely on user-agents handling this header appropriately in order
    to initiate a download of a file to an end-user's local disk.
    An example is
    Content-Disposition: attachment; filename="fname.ext"
    This HTTP response header says to the user agent, 'Don't
    render this response as HTML; instead write the response to a file
    on the user's disk called fname.ext'.
    When the Air HTMLLoader encounters an HTTP response with a
    Content-Disposition similar to the example above, nothing is
    re-rendered (which is the correct behavior), there is no way to
    detect that the attachment Content-disposition header has been
    served (bad), and there is no way to obtain the attachment itself
    (worse).
    The correct behavior for an HTTP client which receives an
    HTTP response parameter of this type can be found in RFC 2616,
    section 19.5.1. It is stated that "If this header is used in a
    response with the application/octet-stream content-type, the
    implied suggestion is that the user agent should not display the
    response, but directly enter a ‘save response as...’
    dialog". I suspect that Adobe hasn't had a chance to implement a
    way for HTMLLoader to notify client code of this situation, or the
    process for getting the HTTP response body.
    Has anyone encountered a work-around? Does anyone know of
    plans in place to correct this bug?

    The problem is that the server script is treating the request as a request for a file to download, rather than as a typical HTTP request/response.  You need to modify the server script so that it doesn't include the Content-Disposition header, there's not much you can do on the client side.

  • Setting path for "Content-disposition" filename

    I'm trying to figure out how to set the filename in the following:
    String path = "/usr/local/jakarta-tomcat-4.1.29/webapps/myapp/my_images.zip";
    response.setContentType("application/octet-stream");
    response.setHeader("Content-disposition","attachment; filename=" +path);The file that I'd like the user to download is called my_images.zip. It resides here: /usr/local/jakarta-tomcat-4.1.29/webapps/myapp/my_images.zip
    However, when I run the servlet, it pops up a dialog box with this as the filename: usrlocal_jakarta-tomcat-4.1.29_webapps_myapp_my_images.zip
    It's replaced the slashes with underscores. What's going on? The zip file resides in the root folder of my app. The servlet is in a subfolder called "fpauto".

    Ah, ok. Right, so when you set that heading what you are saying to the client is: "The response from this web request is actually a file with the following name..."
    For example you could set it to be README.TXT and then use
    response.getWriter().println("Hello World.");as the only other line of your servlet. That would send a text "file" called README.TXT to the client containing the text "Hello World" only. Setting that response header doesn't tell the servlet to do anything other than inform the client what filename to use.
    It would be nice if there was a method called "transmit file" or somesuch, but there isn't. The simplest reason why is that if you just want to send a file you can usually provide it directly from the web (or app) server by putting it into the content. For example create a file my_files.zip in the root of your war and it will typically be made available as a file anyway.
    The assumption is that servlets are for generating content not just sending content that already exists.
    However, if you have a good reason for wanting to do this, you can create a loop that reads in the file and sends its contents to the response's output stream. I usually use the commons-io IOUtil [copy |http://commons.apache.org/io/api-1.4/org/apache/commons/io/IOUtils.html#copy(java.io.InputStream,%20java.io.OutputStream)] functions to do this.
    So why do you want to use a servlet to send "static" content?

  • Missing "Content-Disposition" and attachment's file name

    We're testing OCFO 10.1.3.0.6 with MS Outlook 2003 and found some problems when message with attachments is received.
    If the attachment's file name is encoded and the body part looks like:
    Content-Type: application/msword; name="=?utf-8?B?encoded name?="
    Content-Disposition: attachment; filename="=?utf-8?B?encoded name?="
    everything is OK - the message is displayed as expected and the attachment's file name is decoded right.
    But, if Content-Disposition field is missing, the attachment's file name is not decoded - it's displayed as "=?utf-8?B?encoded name?=" (the name is obviously taken from Content-Type's name parameter), we loose information about file's type and we can't open the attachment.
    It seems that MS Outlook (without OCFO) is "smart" enough to decode Content-Type's name parameter as file name in the absence of Content-Disposition field. The same is true for Thunderbird.
    Any ideas?

    Actually the "name" parameter in Content-Type was declared depricated in RFC 1521 in september 1993, (now belongs to Content-Disposition) so they can be excused in a way....
    Message was edited by:
    user464123

  • Content-Disposition in IE

    Hi
    I want to stream a pdf file and then show in the browser . res.setHeader("Content-Disposition", "inline;filename=temp.pdf;");
    This works with netscape but in IE it shows blank page after starting a Acrobat process.
    But if i use
    res.setHeader("Content-Disposition", "attachment;filename=temp.pdf;"); this works with IE and netscape both . I am not able to figureout what is the problem . Anyone knows solution for this problem ? Please let me know .
    Thanks in advance
    Amit Kumar

    Hi
    I want to stream a pdf file and then show in the
    he browser . res.setHeader("Content-Disposition",
    "inline;filename=temp.pdf;");
    Hi,
    I am currently working with reports being exported to excel
    You can try this :
    res.setContentType("application/pdf");
    I think it should work ....but I am not sure whether the mime type for pdf is ("application/pdf"); or ("application/vnd-pdf");
    try both ....let me noe if fit works ....:)
    cheers

  • Downloading Excel won't work in IE, but works in Netscape.

              Hello:
              I am trying to setup downloading an excel file from a java
              servlet. I have set the content type as follows.
              response.setContentType("application/vnd.ms-excel");
              Note that, this works fine using Netscape. But with IE
              (6.0 / 5.5), it gives the following error:
              Microsoft Excel cannot access the
              file "https://servername.abc.com.......". There are
              several possible reasons:......
              Also, note that if I set the content type to text, then
              the data is properly displayed in the browser.
              Any help is highly appriciated.
              Thanks
              

    This is from and IIS page and I haven't tried in a servlet, but I expect the
              HTTPSerlvetResponse has similar functionality
              All thinigs seem to be need to be set correctly for it to work. Does this
              work in Nutscape 6? I've had to do similar stuff 6 to get it to work.
              Setting the buffer to false is a biggie as well as doing a binary write
              ' Send the HTML page back to the browser.
              Response.Buffer = False
              Response.CacheControl = "private"
              Response.ContentType = "application/vnd.ms-excel"
              Response.AddHeader "content-disposition", "attachment; filename=" &
              strDlReportFileName
              Response.BinaryWrite strHTMLResponse
              Response.End
              HTH
              BTW: I know "ravi" is kinda popular name, but did you every work at
              Spree.com?
              Michael J. Geiser
              "ravi" <[email protected]> wrote in message
              news:3f0d8ce2$[email protected]..
              Hello:
              I am trying to setup downloading an excel file from a java
              servlet. I have set the content type as follows.
              response.setContentType("application/vnd.ms-excel");
              Note that, this works fine using Netscape. But with IE
              (6.0 / 5.5), it gives the following error:
              Microsoft Excel cannot access the
              file "https://servername.abc.com.......". There are
              several possible reasons:......
              Also, note that if I set the content type to text, then
              the data is properly displayed in the browser.
              Any help is highly appriciated.
              Thanks
              

  • Can't get the attachment filename out of a Part (with non ascii characters)

    Hello, all and happy new year :)
    My issue is with non ascii filename in attachments... Yes i've read the FAQ : http://www.oracle.com/technetwork/java/faq-135477.html#encodefilename
    I can't get the filename out of the BodyPart for those kind of attachments
    here's my unit test :
         * contains various parts from various mailer encoded in different ways...
         private enum EncodedFileNamePart{
              OUTLOOK("Content-Type: text/plain;\n name=\"=?iso-8859-1?Q?c'estd=E9j=E0no=EBl=E7ac'estcool.txt?=\" \nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment;\n filename=\"=?iso-8859-1?Q?c'estd=E9j=E0no=EBl=E7ac'estcool.txt?=\" \n\nnoel 2010\n","c'estdéjànoëlçac'estcool.txt"),
              GMAIL("Content-Type: text/plain; charset=US-ASCII; name=\"=?ISO-8859-1?B?ZOlq4G5v62znYWNlc3Rjb29sLnR4dA==?=\"\nContent-Disposition: attachment; filename=\"=?ISO-8859-1?B?ZOlq4G5v62znYWNlc3Rjb29sLnR4dA==?=\"\nContent-Transfer-Encoding: base64\nX-Attachment-Id: f_giityr5r0\n\namluZ2xlIGJlbGxzIQo=\n","déjànoëlçacestcool.txt"),
              THUNDERBIRD("Content-Type: text/plain;\n name=\"=?ISO-8859-1?Q?d=E9j=E0no=EBl=E7acestcool=2Etxt?=\"\nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment;\n filename*0*=ISO-8859-1''%64%E9%6A%E0%6E%6F%EB%6C%E7%61%63%65%73%74%63%6F;\n filename*1*=%6F%6C%2E%74%78%74\n\njingle bells!\n","déjànoëlçacestcool.txt"),
              EVOLUTION("Content-Disposition: attachment; filename*=ISO-8859-1''d%E9j%E0no%EBl.txt\nContent-Type: text/plain; name*=ISO-8859-1''d%E9j%E0no%EBl.txt; charset=\"UTF-8\" \nContent-Transfer-Encoding: 7bit\n\njingle bells\n","déjànoël.txt"),
              String content=null;
              String target=null;
              private EncodedFileNamePart(String content,String target){
                   this.content=content;
                   this.target=target;
              public Part get(){
                   try{
                   ByteArrayInputStream bis = new ByteArrayInputStream(this.content.getBytes());
                   Part part = new MimeBodyPart(bis);
                   bis.close();
                   return part;
                   catch(Throwable e){
                        return null;
              public String getTarget(){
                   return this.target;
         @Test
         public void testJavamailDecode() throws MessagingException, UnsupportedEncodingException{
              System.setProperty("mail.mime.encodefilename", "true");
              System.setProperty("mail.mime.decodefilename", "true");
              for(EncodedFileNamePart part : EncodedFileNamePart.values())
                   assertEquals(part.name(),MimeUtility.decodeText(part.get().getFileName()),part.getTarget());     
    I take a NullPointerExcepion in the decodeText because getFileName() return null for the EVOLUTION case, and work well with OUTLOOK, THUNDERBIRD and GMAIL.
    Evolution's content type is "Content-Disposition: attachment; filename*=ISO-8859-1''d%E9j%E0no%EBl.txt" wich doesn't look like the other (looks like the RFC 2616 or RFC5987 to do it.)
    How can i handle this situation except by writting my own decoder?
    Thanks for your answers!
    Edited by: user13619058 on 4 janv. 2011 07:44

    Set the System property "mail.mime.decodeparameters" to "true" to enable the RFC 2231 support.
    See the javadocs for the javax.mail.internet package for the list of properties.
    Yes, the FAQ entry should contain those details as well.

  • How to specify the charatcer encoding for the parametes Content-Disposition

    I want to download a file with chinese name .
    response.setHeader("Content-Disposition","attachment; filename=" + fileName);
    the above part of code is working fine for english file names. but i am facing problem when i try to get file with chinese name .
    The pop up window is not defaulting with the chinese name .
    When i searched for net , in one rfc it was specified how to do that one.
    http://www.faqs.org/rfcs/rfc2184.html.
    I tried it but .. could not able to solve the problem.

    Hi,
    Am facing similar problem with russian and japanese characters in file name.
    I tried the UrlEncoder.encode(filename, "utf-8') api to encode the file name. This worked fine with IE but firefox and safari shows junk for japanese/russian characters.
    Anyone having an idea abt this?
    Thanks,
    Kapil

  • Bug: DocumentManager does not emit Content-Disposition header

    Good afternoon,
    I have a process with an output variable of type Document: this document has a defined filename. When invoking the process, instead of downloading the file with the defined filename, I was receiving a file with a name that looks like an MD5 hash.
    The fault for this lies with the DocumentManager application: it does not emit the content disposition header that would suggest to the browser what the real name of the octet-stream is. As such, without this header, the user agent will assume that the file-name is the endpoint name.
    The trace of the HTTP exchange is below:
    GET http://HOST:8080/rest/services/APP/SERVICE:1.0?q=83
    Cache-Control     no-cache, must-revalidate
    Date              Wed, 17 Nov 2010 12:54:29 GMT
    Pragma            no-cache
    Transfer-Encoding chunked
    Location          http://HOST:8080/DocumentManager/docm$(NUMBER)/$(HASH)?type=$(TYPE)
    X-Powered-By      Servlet/2.5 JSP/2.1
    GET http://HOST:8080/DocumentManager/docm$(NUMBER)/$(HASH)?type=$(TYPE)
    Date              Wed, 17 Nov 2010 12:54:35 GMT
    Transfer-Encoding chunked
    Content-Type      application/vnd.ms-excel
    X-Powered-By      Servlet/2.5 JSP/2.1
    The 2nd HTTP request should have included the specified header, like so:
    Content-Disposition: attachment; filename=MyExcel.xls
    RFC 2183: The Content-Disposition Header Field
    Best regards,

    Hi Robert,
    thanks for the reply. This is certainly a different aspect of the problem. The HTTP response that serves the dynamic portion (the one with the timestamp) has the response headers:
    HTTP/1.1 200 OK
    Date: Wed, 21 Jan 2015 18:05:53 GMT
    Server: Apache/2.2.29 (Unix)
    X-Powered-By: PHP/5.3.29
    Cache-Control: max-age=100000, public
    Keep-Alive: timeout=3, max=95
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: application/xml
    So it is marked as cacheable. 
    My expectation now is this:
    - when clicking the "refresh" link in the markup, there should be no new timestamp. Reason is that the dynamic part should have been cached and I would expect the XSLT engine to use the browser's caching layer when fetching fragments
    - when hitting "F5" I would expect a revalidation request to be send to the server (e.g. max-age=0 or if-modified-since). Then the server can revalidate the fragment. In my example case the fragment would be served in any case, so I would expect a
    new timestamp
    - when hitting "CTRL+F5" I would expect a request with "cache-control: no-cache" that enforces the server side caches to always return new content. I would expect a new timestamp in this case.
    What I observe is that:
    - Chrome and FF work as expected
    - IE (10/11) will always fetch the dynamic fragment, so I will even see a new timestamp when clicking the refresh link. Also the "if-none-match" header in the "F5" case is NOT forwarded to the dynamic fragment (potentially because it is
    not cached in the browser at all)
    Carsten

  • PDF content disposition on IE

    Hi,
    I am having difficulties in displaying PDF content from JSP. Obviously URL ends with mypdffile.jsp. From the JSP, I set attributes as follows. It works as intended on Firefox. Not on IE;
    response.setContentType("application/pdf;charset=UTF-8");
    response.setHeader("Content-Disposition", "inline;filename=\"Document.pdf\""); Any suggestions how I can fix this mess?

    On IE, it shows nothing! I can see that it reads something then nothing shows up. It is meant to display inside the viewing frame without creating external frames. If I change to "Content-disposition: attachment; filename=ddd.pdf", it comes out with PDF view frame. If you move the frame, you see lots of dirty traces on Windows frame!
    It may IE is not handling extension well.Or size information may be required.
    JSP is convenient to write changeable reports. PDF is generated using iText.
    Regards.

  • Download "Content-Disposition" to Excel

    I have a user who was having trouble getting an Excel file to download properly. When she clicked on the web link created by my procedure, her Excel file would download all the columns into one field. For myself, and most other users, it downloads normally with all the columns and fields where they should be. She was also missing the prompt asking if you wanted to open or save the file. It was just downloading to Excel right away.
    Now, the user said she did not have this problem with all her Excel downloads, just this one. So I looked at the program that had the Excel download that worked for her and compared it to the one that didn't.
    And there was a difference.
    The download that did NOT work for her had this line of code: htp.print('Content-Disposition: inline; filename='||v_file_name1);
    The download that DID work for her had this code: htp.print('Content-Disposition:attachment; filename='||v_file_name1);
    In the program that wasn't working for her I replaced the part of Content-Disposition with "attachment" instead of "inline". That seemed to do it. Nothing more needs to be done, but I dont' really know why it worked. I can't seem to find a definintion of what an "inline" Content-Disposition means vs. "attachment". Anyone know? Thanks!
    Oh, and here's the surrounding owa_util code in case that helps make it more clear where it was coming from:
    owa_util.MIME_HEADER('text/comma-delimited', FALSE);
    htp.print('Content-Disposition:attachment; filename='||v_file_name1);
    owa_util.HTTP_HEADER_CLOSE;
    Message was edited by:
    user527082

    I have a user who was having trouble getting an Excel file to download properly. When she clicked on the web link created by my procedure, her Excel file would download all the columns into one field. For myself, and most other users, it downloads normally with all the columns and fields where they should be. She was also missing the prompt asking if you wanted to open or save the file. It was just downloading to Excel right away.
    Now, the user said she did not have this problem with all her Excel downloads, just this one. So I looked at the program that had the Excel download that worked for her and compared it to the one that didn't.
    And there was a difference.
    The download that did NOT work for her had this line of code: htp.print('Content-Disposition: inline; filename='||v_file_name1);
    The download that DID work for her had this code: htp.print('Content-Disposition:attachment; filename='||v_file_name1);
    In the program that wasn't working for her I replaced the part of Content-Disposition with "attachment" instead of "inline". That seemed to do it. Nothing more needs to be done, but I dont' really know why it worked. I can't seem to find a definintion of what an "inline" Content-Disposition means vs. "attachment". Anyone know? Thanks!
    Oh, and here's the surrounding owa_util code in case that helps make it more clear where it was coming from:
    owa_util.MIME_HEADER('text/comma-delimited', FALSE);
    htp.print('Content-Disposition:attachment; filename='||v_file_name1);
    owa_util.HTTP_HEADER_CLOSE;
    Message was edited by:
    user527082

  • Problem with non-ASCII file name in content disposition header

    Hi All,
    I am facing some problems with the non-ASCII file name incase of content-disposition header. I read from the RFC 2183 that if the file name contains non-ASCII characters then the same should be encoded before sending to browser. I did the same but realized 2 problems:
    1. The name of the file is truncated in case the file name is slightly long for e.g. �����������j�b�g��������������������������.txt
    2. Also when the same file is opened in notepad, the title is showing encoded name %E6%9C%80%E4%B8%8A%E4%BD%8D.....
    Overall, I feel that the browser is not understanding or responding to the encoded header values.
    Is there any solution to this problem? I am using Microsoft IE 6.0.
    The code snippet is given below:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              String fileName = "�����������j�b�g��������������������������.txt";          
              fileName = URLEncoder.encode(fileName, "UTF-8");
              resp.setCharacterEncoding("UTF-8");
              resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
              resp.setContentType("application/download-binary");
              String s = "This is inside txt file";
              resp.getOutputStream().write(s.getBytes("UTF-8"));
              return;
         }Any help or pointer would be highly appreciated.
    Thanks and Regards,
    Ashish

    The MIME standards for non-ASCII filenames are not widely implemented.
    Many mailers use an ad hoc method for encoding filenames. JavaMail
    supports both methods, but you need to set properties, such as the
    mail.mime.encodefilename property. See the JavaMail javadocs for
    the javax.mail.internet package.

  • Content-disposition header - office 2007 warning

    When I set the response header in the following way- using content-disposition inline- and try to open a xls file, I don't get the open/save dialog due to content-disposition but a warning message comes from office 2007 saying "The file you're trying to open is in a different format..."
    response.setHeader{"content-disposition","inline;filename="+filename}Whereas, for the response header set in this way- using content-disposition attachment- the open/save dialog appears without being followed by a warning from office 2007.
    response.setHeader{"content-disposition","attachment;filename="+filename}Is there anyway I can avoid open/save dialog due to content-disposition and still not get the warning from office 2007?
    Edited by: 1normalguy on Nov 18, 2008 10:54 PM

    The problem is that "xls" is a different format. Office 2007 uses xlsx because the format (for all Office documents) has been completely altered in Office 2007. They are no longer even close to being the same thing, anymore.
    Edit: Gods! So many typos in so small a text!

Maybe you are looking for

  • Issues with itunes 10.5 on Windows 7 (32 Bit) When Trying to sync iphone 4S or older

    I see a lot of people out there, specifically windows OS owners (xp all the way to 7), having issues with iTunes 10.5.  Here are the following issues I've encountered (some may only have one problem, others my have a combo pack of problems). 1. iphon

  • Ipod suffle 3g recognized by iTunes but doesn't start! (water damage)

    My ipod shuffle 3G has a water damage. it shows the red/pink indicator. It doesn't starts but it connects to iTunes. I can move songs to my iPod shuffle and other stuffs. But it doesn't start. I have opened my iPod shuffle. It had green sedimentation

  • Crashing problem EXC_BAD_ACCESS (SIGABRT)

    Crashing reporter is offline/page not found? Have a problem with After Effects CS5 crashing randomly - here's the logs from the last two: Is it a corrupted font? I have removed one with was a serious error, but want to resolve this as it's slowing my

  • Root element charts not defined in schema error??

    My xsd file is <?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://www.datastay.com/schema" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:target="http://www.datastay.com/schema">      <xs:eleme

  • Songs in Wrong Order for iTunes 7

    I have my music sorted by album, and when I upgraded to the new version of iTunes, about ten or so albums are randomly in the wrong order. I have the track numbers listed next to each song, and they are correct, but for some reason they are ordered,