Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing browser download prompt 2

Status
Not open for further replies.

bjanssen

Programmer
Mar 11, 2001
10
AU
Hi,
I am writing a web site with JSP's and java servlets running on WebSphere. I am trying to set up a ling to a file that will ALWAYS prompt the user if they would like to open or save the file. At the moment, if the link is a .xls file, for example, it will open the file in Excel. Is there any way of forcing the browser to bring up the save or open question box? I have tried response.setContentType("none/none") but I think I'm barking up the wrong tree. Hope you can help, Brett.
 
Try the response.setContentType("application/octet-stream");

Otto
 
Maybe do you use IEx.x? This browser always use the file type association at download not the content header. Try to change the file extension.

Otto
 
Yes, I am using IE5.5 at the moment. I considered changing the file extension, but that would confuse the people who are using this app if they have to change extensions all the time. In IE, is there then no way of forcing that prompt? That seems a little stupid!
 
Try this:

response.addHeader("content-disposition", "attachment; filename=whatever.xls");
 
Hi,

I am facing the same problems as u'r for a Forceful download of an XML file. I tried out u'r method of response.addHeader . i am using JSP in Solaris for x86 and JavaWebServer2.0 with Java 1.2 as server. but it gives the following error.
" Method addHeader(java.lang.String, java.lang.String) not found in interface javax.servlet.http.HttpServletResponse. "

what should be the problem ? Is there anyway i can do it for IE too as it recognizes XML. Regards,
Madhu Menon.
 
Hmmm that is very strange. HttpServletResponse.addHeader( String, String ) is a standard J2EE method. Maybe you can try setHeader instead:

response.setHeader("content-disposition", "attachment; filename=whatever.xls");

This ia actually better because if there was already somehow a content-disposition header send, this would override it.

Maybe you are using an old Servlet API or something. If setHeader does not work either, I would recommend upgrading to Java 1.3.



 
Thanks Gerald .setHeader(String , String) worked fine with IE and XML. Iwill try out Java 1.3 for .addHeader(String, String)


Regards,
Madhu Menon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top