• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

repost with more detail on problem of download servlet in Internet Explore

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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="/download/<%= currentDoc.doc_id %>/<%= currentDoc.name %>">
on the browser, it will be sth like <a href="/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
// set content type
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=\""+tmp_name+"\"");
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 7.0, when I click on the link, Netscape prompts me to choose "open using Word" or "save this file to disk". That's exactly the behavior I want. <br>
However in IE 5.50, the behavior is VERY STRANGE.
First, when I click on the URL, the popup window asks me to "open the file from its current location" or "save the file to disk". It also says "You have chosen to download a file from this location, ...(some url).. from localhost"
(1) If I choose "save the file to disk", it will save the rendered "download.jsp" (ie, the currect page with URL I just clicked, which isn't what I want).
(2)But if I choose "open the file from its current location", the 2nd popup window replaces the 1st, which also has the "Open ..." and "Save.." options, but it says "You have chosen to download a file from this location, MYFILE.doc from localhost". (notice it shows the correct file name now)
(3) If I choose "Save..." on the 2nd window, IE will save the correct file which is "myfile.doc"; if I choose "Open ...", a 3rd replaces the 2nd window, and they look the same, and when I choose "Open..." on the 3rd window, IE will use Word to open it.
any ideas?
 
Peter W Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fixed it myself.
 
This tiny ad is guaranteed to be gluten free.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic