wood burning stoves 2.0
The moose likes HTML, CSS and JavaScript and the fly likes problem with file download dialogue box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem with file download dialogue box" Watch "problem with file download dialogue box" New topic

problem with file download dialogue box

kumar kiran

Joined: Sep 15, 2008
Posts: 11
For my java application i am using tomcat5.0 server and struts framework.I am facing one problem with file download dialogue box.In a jsp i am having a link, after clicking that link through a javascript function submitting the form the jsp and then control is going to struts action class.In that action class i using the following lines code to get file download dialogue box.

response.setHeader ("Content-Disposition","attachment;filename=\""+filename+"\"");
InputStream in = new FileInputStream(f);
ServletOutputStream outs = response.getOutputStream();
int bit = 256;
try {
while ((bit) >= 0) {
bit = in.read();
} catch (IOException ioe) {
once i save or open or cancel that dialogue box and then click any submit button in that jsp again the same dialogue box is coming .I am not able to do anything with submit buttons after opening the dialogue box....please help me on this regard..thanks in advance.

scjp1.5(87)<br />scwcd in progress....
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Did you write that code inside the JSP file or so? You should not write Java code in a JSP file. Java code belongs in a Java class. If it is actually been located in a Java class, then your code flow is simply wrong.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

To elaborate on Bauke's correct answer.

JSP is a poor choice of technology for streaming binary data to a client (browser) because it was designed for building up textual responses such as HTML and Javascript. The problems people run into are usually caused by the JSP compiler inserting its own markup and or white space into the response. This causes the response to be returned via a printWriter object instead of a raw servlet output stream.

If you need to return binary data, it's much simpler and cleaner to do so with a servlet.
We have an example application, all packed up in a war and ready to drop into a container and run, in our codeBarn.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
kumar kiran

Joined: Sep 15, 2008
Posts: 11
Thanks for the response.sorry guys, i didn't say that i wrote binary code generation in struts action class.I didn't write in the jsp.The control process is when i click the link i am calling a javascript function and submitting the form, then control goes to struts action class there i wrote the code for binary stream.then i am successfully getting the dialogue box.After saving or opening or cancelling ,if i click any submit button in that jsp i am getting the same dialogue box.that's the problem.....
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

OK, this sounds more like an issue on the client side.

I'm going to move this to our HTML forum for you.
I agree. Here's the link: http://aspose.com/file-tools
subject: problem with file download dialogue box
It's not a secret anymore!