Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem while downloading a tab delimited file to excel using Servlet

Reply
Thread Tools

Problem while downloading a tab delimited file to excel using Servlet

 
 
Niraj Agarwal
Guest
Posts: n/a
 
      01-12-2004
Hi,

I am trying to download a tab-delimited file to client machine using
servlet.
I am using IE5.5 browser to test the application.
Here is the code in my servlet, which is sending the file to the
client machine.

ServletOutputStream out = response.getOutputStream();

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline;
filename=\""+getFileNameOnly()+".xls\"");

// Generate tab delimited string buffer
StringBuffer sbRet = generateXlsFormat();

// Send it to client
out.write(sbRet.toString().getBytes());

out.close();

I want to download (open) this file directly to a new browser window,
or in excel with the filename i am passing from the servlet.

The problem is that, it opens the file in excel but the file name is
the url that i posted to get this file, it is not that i set in
servlet.

I tried all permutations and combinations but nothing is working.

Can someone please help me out to resolve this problem?

Thanks in advance,
Niraj
 
Reply With Quote
 
 
 
 
Gregory A. Swarthout
Guest
Posts: n/a
 
      01-12-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Niraj Agarwal) wrote in message news:<(E-Mail Removed). com>...
> Hi,
>
> I am trying to download a tab-delimited file to client machine using
> servlet.
> I am using IE5.5 browser to test the application.
> Here is the code in my servlet, which is sending the file to the
> client machine.
>
> ServletOutputStream out = response.getOutputStream();
>
> response.setContentType("application/vnd.ms-excel");
> response.setHeader("Content-Disposition", "inline;
> filename=\""+getFileNameOnly()+".xls\"");
>
> // Generate tab delimited string buffer
> StringBuffer sbRet = generateXlsFormat();
>
> // Send it to client
> out.write(sbRet.toString().getBytes());
>
> out.close();
>
> I want to download (open) this file directly to a new browser window,
> or in excel with the filename i am passing from the servlet.
>
> The problem is that, it opens the file in excel but the file name is
> the url that i posted to get this file, it is not that i set in
> servlet.
>
> I tried all permutations and combinations but nothing is working.
>
> Can someone please help me out to resolve this problem?
>
> Thanks in advance,
> Niraj



We do virtually the same thing and it works. The only differences I
see
are:

1) We use "application/x-ms-excel" for the content-type.
2) We set the headers "Cache-Control" and "Pragma" to "".
3) Our "Content-disposition" header has the lower-case "d".
4) We set the content length a la:
response.setContentLength(sbRet.toString().getByte s().length);
5) We flush the output after writing it a la:
response.getOutputStream().flush();

See if one or more of the above fixes your problem.

Greg
 
Reply With Quote
 
 
 
 
Niraj Agarwal
Guest
Posts: n/a
 
      01-13-2004
Thanks Greg,

I tried all things you mentioned, but it is still the same. Can you
share your code with me if possible. Also can it be the problem with
AppServer. I am using WebLogic 8.1.

Also when i use "Content-disposition-type" as "attachment" instead of
"inline", it shown "Save As" dialog, but if i use "open from current
location" option it ask for 3 times before opening the file in excel,
but this time it uses the right file name.

Thanks,
Niraj

(E-Mail Removed) (Gregory A. Swarthout) wrote in message news:<(E-Mail Removed) om>...
> We do virtually the same thing and it works. The only differences I
> see
> are:
>
> 1) We use "application/x-ms-excel" for the content-type.
> 2) We set the headers "Cache-Control" and "Pragma" to "".
> 3) Our "Content-disposition" header has the lower-case "d".
> 4) We set the content length a la:
> response.setContentLength(sbRet.toString().getByte s().length);
> 5) We flush the output after writing it a la:
> response.getOutputStream().flush();
>
> See if one or more of the above fixes your problem.
>
> Greg

 
Reply With Quote
 
Niraj Agarwal
Guest
Posts: n/a
 
      01-13-2004
Thanks Greg,

I tried all the things you mentioned but still the result is the same,
file opened in excel does not have right file name. Can you share your
code that is working fine, if you can. Can it be problem with
Application server, we are using Weblogic 8.1.

Niraj


(E-Mail Removed) (Gregory A. Swarthout) wrote in message news:<(E-Mail Removed) om>...
>
> We do virtually the same thing and it works. The only differences I
> see
> are:
>
> 1) We use "application/x-ms-excel" for the content-type.
> 2) We set the headers "Cache-Control" and "Pragma" to "".
> 3) Our "Content-disposition" header has the lower-case "d".
> 4) We set the content length a la:
> response.setContentLength(sbRet.toString().getByte s().length);
> 5) We flush the output after writing it a la:
> response.getOutputStream().flush();
>
> See if one or more of the above fixes your problem.
>
> Greg

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML -> Tab-delimited text file (using lxml) Gibson Python 2 11-19-2008 05:33 PM
Perl/unix script to convert a fixed width file to a tab delimited file Srikant Perl Misc 1 09-29-2007 02:32 PM
convert non-delimited to delimited RyanL Python 6 08-28-2007 12:06 AM
Problem reading tab delimited file iamreallynewhere@sbcglobal.net Java 5 05-10-2005 05:39 PM
Is there any perl script for converting XML file to tab-delimited file ? gongwuming@hotmail.com Perl Misc 1 04-14-2004 05:15 PM



Advertisments