I have trouble to make my download
servlet work in Internet Explore. I have gone through all the previous postings and done some research on the internet, but still can't figure out the solution. <br>
I have a
jsp page called "download.jsp" which contains a URL to download a file from the server, and I wrote a servlet (called downloadServlet) to look up the corresponding file from the database based on the URL and write the file to the HTTP output to send it back to the browser. <br>
the URL in download.jsp is coded like <a href="http://localhost:8100/download/<%= currentDoc.doc_id %>/<%= currentDoc.name %>">
on the browser, it will be sth like <a href="http://localhost:8100/download/87/myfile.doc">, the number 87 is my internal unique number for a file, and "myfile.doc" is the real document name. <br>
in my web.xml, /download/ is mapped to downloadServlet <br>
the downloadServlet.java looks like
-----------------------------------------
tem_name = ... //read DB for file name
if ( tmp_name.endsWith(".doc")) {
response.setContentType("application/msword");
}
else if ( tmp_name.endsWith(".pdf")){
response.setContentType("application/pdf");
}
else if ( tmp_name.endsWith(".ppt")){
response.setContentType("application/vnd.ms-powerpoint");
}
else if ( tmp_name.endsWith(".xls")){
response.setContentType("application/vnd.ms-excel");
}
else {
response.setContentType("application/download");
}
// set HTTP header
response.setHeader("Content-Disposition",
"attachment; filename=\""+ele.upload_location+"\"");
OutputStream os = response.getOutputStream();
//read local file and write back to browser
int i;
while ((i = is.read()) != -1) {
os.write (i);
}
os.flush();
------------------------------------------
Everything works fine in Netscape, but in IE, when I click on the URL, it downloads the "download.jsp" file instead of the "myfile.doc". It will work if I right click and choose "save file as ...".
Please help me.
thanks,
Peter