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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 61450
    
  67

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.
 
jQuery in Action, 2nd edition
 
subject: File download problem