Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

file download is not working  RSS feed

anna malai
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a file in the server which is to be downloaded.
for that one link with the file name is provided. on cliking the link the following code is called.

ServletOutputStream sos=null;
response.setHeader("Content-Disposition","attachment; filename="+st/*.substring(temp+1)*/);
FileInputStream bufReader = new FileInputStream(request.getRealPath(st));
sos = response.getOutputStream();

the problem is
1. when the save as dialogue pops up it displays the filename to be downloaded correctly for the first time. when save button is cliked it again asks with the name of the html page.

2. when the save button is pressed for second time it saves the html file.

3. some times an error " the page you are looking for is temporarily unavailable or removed" is displayed by the browser IE 5.0 but not in IE 6.0
both in win2000 os.

4. the same code had worked fine already.

how to solve these?
Ben Souther
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert on Java streams so I'm not going to try to figure out what's wrong with your code. I will, however, give you a piece of code that's working for me.

I will mention two things that I noticed about your code.
1.) you're flushing the buffer before you've started reading into it.
I don't know if this is causing a problem but it's certainly not necessary.

2.) Your variable names (combined with the lack of UBB code tags) make it very difficult for someone else to read your code.
You're reading and writing chars as ints but naming them "line" (it's possible to read from a text file one line at a time and at first glance, I thought that's what you were doing.)
You've also named a FileInputStream "bufReader" which makes it look, at first glance, like you're using an instance of

I normally don't pick nits but in this case, I think these issues are going to keep you from getting help with your code.
[ May 07, 2005: Message edited by: Ben Souther ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!