File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problem with servlet streaming CSV files in WinXP SP2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with servlet streaming CSV files in WinXP SP2" Watch "Problem with servlet streaming CSV files in WinXP SP2" New topic
Author

Problem with servlet streaming CSV files in WinXP SP2

Chris OBrien
Greenhorn

Joined: Oct 22, 2004
Posts: 3
Alright, I have an interesting problem, which is only an issue with Windows XP SP2 and Internet Explorer.

We have a servlet which reads report files (both pdf and csv) from a directory outside of our EAR deployment. The servlet reads the files, and just writes it out to the browser.

This worked perfectly before, but since we upgraded to Windows XP SP2, along with an Internet Explorer update, the csv files come back messed up.

When the csv file opens, it opens inside Excel... inside the browser, which is what we want (and how it always worked).

However, now with the new upgrades, instead of being properly formatted (comma delimited fields are in separate cells), each line of data in the CSV file is jammed inside the first cell in Excel. The csv file itself is perfectly formatted, because if I open the csv in Excel or IE manually, it is displayed properly.

It is my understanding that with SP2, a 'fix' was added to remove a vulnerability with the MS Text engine, so 'strict' mime types are required.

We are currently doing:
response.setContentType( "text/csv" );
response.setHeader("Content-Disposition","filename=report.csv" );

I have also tried making the content type application/octet-stream with no luck.

This is a weird situation, and I can't find anything on Google about it.
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
You could try using


Cheers!<br /><b>Annie</b>
danny liu
Ranch Hand

Joined: Jan 22, 2004
Posts: 185
However, now with the new upgrades, instead of being properly formatted (comma delimited fields are in separate cells), each line of data in the CSV file is jammed inside the first cell in Excel. The csv file itself is perfectly formatted, because if I open the csv in Excel or IE manually, it is displayed properly.


IE opens the .csv file depending on a regional parameter. You can open "Regional Options", pick up the "Numbers" tab, and then configure "List Separator" to comma.

This works fine. However, it requires users do the same procedure on their computers, which seems impossible.

Another option is to create excel file instead of .csv file. You can use
POI from Apache.

Hope this helps.

Dan
Chris OBrien
Greenhorn

Joined: Oct 22, 2004
Posts: 3
Originally posted by Annie Smith:
You could try using


Just tried this, it now brings up the Open/Save dialog instead of opening the file inline. Good news is, the file opens in Excel properly. Bad news is, we need it inline. This might have to do though, thanks.

Originally posted by danny liu:
IE opens the .csv file depending on a regional parameter. You can open "Regional Options", pick up the "Numbers" tab, and then configure "List Separator" to comma.

This works fine. However, it requires users do the same procedure on their computers, which seems impossible.

Another option is to create excel file instead of .csv file. You can use
POI from Apache.


I tried using the List separator in the regional options control panel, and it is already set to a comma, so that didn't do anything.

As far as creating an Excel file, that's definitely not going to work. This was a last minute find, and needed a quick fix. Something to look forward at in the future though, thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Change it to:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Chris OBrien
Greenhorn

Joined: Oct 22, 2004
Posts: 3
Originally posted by Ben Souther:
Change it to:


Tried this as well, it does the same thing as before, opens the CSV file inline w/ Excel, but has all the data in the first cell of each row
Jamie Grant
Greenhorn

Joined: Aug 25, 2004
Posts: 2
I've got the same issue, and it seems that when the request goes through the weblogic apache plugin, the header gets stripped out of the attached file. Connecting to weblogic directly without using the plugin works fine. Have no clue how to solve it....which obviously doesn't help any.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I went through a similar incident a while back. Changing the delimiters got it to work in Excel but broke it for Open Office. I finally gave up and formatted with HTML tables. Both Open Office and Excel can read them and I haven't had a problem since.

The only downside is data bloat.
Also, the data I was working with never has HTML characters that need to be escaped.
 
jQuery in Action, 2nd edition
 
subject: Problem with servlet streaming CSV files in WinXP SP2