• Post Reply Bookmark Topic Watch Topic
  • New Topic

Internet Explorer corrupts filename in download servlet

 
Florian Mutschelknaus
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

after days reading in the net i still have a problem and hope someone of you guys can help me.

I wrote a simple download servlet called SaveCSVServlet.java which looks like this:



I call that servlet from Javascript with window.location = ....../savecsv?data= .....
Just the normal way i think.
So the servlet is working well in Firefox,Chrome etc. but not in Internet Explorer

When the save file dialog pops up the filename looks like:
test.csv or whatever.csv... so just normal and i can download the file.

When it comes to the Internet Explorer the filename looks like:
main_jsp?mode=Detailansicht5and5area=Stadt5and5indi=Durchschnittsalter5and5id=A5and5detailView=true&fileName=Detailansicht_Stadt_A_Bielefeld_2013

So this is obvious the url of the servlet call and not the filename.
The strange thing is, i am using exactly the same method to call Javascript and then calling the servlet. Sometimes it is working with IE and sometimes not, even on the same page.

I tried all that i could find with response.setHeader and setContentType, nothing works.

Has someone any idea how i can solve that, or what is a better way to do it.

Thank you for your response



 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm rather confused about your question. You showed us a lot of code, but as far as I can see you are complaining that the value of



is sometimes not what you are expecting. Am I right?

Edit: wait a minute, that can't be all of it because you also have this code:



which does something unknown to that value. I also have to say that I don't understand why you're trying to set the file name in the Content-Disposition when the user has already chosen the file where the data is going to be sent, but then there's some Javascript business going on which I don't understand either.
 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As if IE (at least some version ) would give the absolute path name along with a file when uploading a file in contrary to other browsers which give just the file name (without path).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Jozsef Balazs wrote:As if IE (at least some version ) would give the absolute path name along with a file when uploading a file in contrary to other browsers which give just the file name (without path).

This issue has nothing to do with uploading files.
 
Florian Mutschelknaus
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul Clapham,

thanks for your reply.

I am receiving the filename from Javascript, the filename depends on the table that is going to be saved as .csv file.
In the servlet the variable filename has the right value at all times (i debugged that).

Then i flush the outputstream and when it comes to the file download dialog, the filename is corrupted, only when i use IE, but as well not every time.

Like i have written in my first post, normally filename should look like this: Hochzoll_Indikatoren.csv .... for example
but sometimes (not every time) it looks like the url of the next call, like main_jsp?mode=Detailansicht5and5area=Stadt5and5indi=Durchschnittsalter5and5id=A5and5detailView=true&fileName=Detailansicht_Stadt_A_Bielefeld_2013
So this is obviously not a .csv file.

The question is why this happens, because it is the same function for every file download and it is working well in all other browser all times.

The method javascriptHelper.getDecodedAdress is just for decrypting the url parameters. It had something to do with special character like ä,ü,ö etc.
I found out where to set UTF-8 URL-encoding in JBoss so this is quit old and not necessary any more, just forget about that.
 
Florian Mutschelknaus
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention,

even when i use a fix filename for the .csv file, like test.csv or something the phenomenon exists. So it has nothing to do with the filename.
 
Florian Mutschelknaus
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to let you know that i found the source of this problem.

I called the servlet in Javascript like this: window.location = jQuery.getContextPath() + "/savecsv?contentHeader="+contentHeader+"&area="+area+"&id="+id+"&areaName="+areaName+"&year="+year+"&fileName="+csvFileName+"&data="+data;

As i mentioned, it was no problem for all browsers except of IE.
I think IE has problems with some characters in the url, or with the actual length of it, i am not sure about. It is not that the url extended 2000 chars.

So i changed the call to:



where addHidden function looks like this:



This solved the problem for me.
I hope it will help someone else.

Greetings
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!