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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "File  download problem" Watch "File  download problem" New topic

File download problem

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear friends,

I have a link in a JSP. On clicking it an HTML file gets downloaded. When i click the link, the file download dialog box appears with the Open,Save,Cancel options.

When i click the Open button, the HTML file gets opened in the same window. I want to avoid this one.
How to make the file open in a new window, when the user clicks Open button from the file download dialog box? I'm using IE 7.0.

Kindly provide your help.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Look at the target attribute for either the anchor tag or the form tag.
Moving to HTML/Javascript

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mehul Wani

Joined: Mar 18, 2008
Posts: 18
Hi Vijay,

Add this line to the the HTML page to be opened in new window.

response.addHeader("Content-disposition","attachment; filename = myFilename.xls");

Put this code in a jsp scriplet.

Hope this is of some help for you.
Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178

Thanks for your reply. But the solution provided by you didn't work. Perhaps i didn't understand it properly.

Could anyone please explain a little bit more on what exactly to do?
Can i solve the problem by writing it in Action class?

[ March 20, 2008: Message edited by: vijaychandran rajagopalan ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60785

Ben gave you the solution to the problem.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mehul Wani

Joined: Mar 18, 2008
Posts: 18

It seems your's is an Struts application. As you are using action class,
add this line in your action class,
response.addHeader("Content-disposition","attachment; filename = myFilename.xls");

before in_mapping.findForward();
Note that this will work only if you are forwarding the request through action class and not directly to the html page.
Feel free to get more details if needed.
Consider Paul's rocket mass heater.
subject: File download problem
Similar Threads
while opening csv file, dialog box opens twice
File download and request Forward
How to avoid download open/Save dialog box?
issue with open/save dialog
File Download Dialog