File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "File  download problem" Watch "File  download problem" New topic
Author

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.
Regards,
Vijay
Ben Souther
Sheriff

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
Greenhorn

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
Hi,

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?


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

Joined: Jan 10, 2002
Posts: 60756
    
  65

Ben gave you the solution to the problem.


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

Joined: Mar 18, 2008
Posts: 18
Vijay,

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
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