File Download from a servlet


Web tier: servlets, JSP, Web frameworks: File Download from a servlet

  1. File Download from a servlet (3 messages)

    I am facing error while saving the file from the browser to the client side. I have an xml data that is created by a servlet. I have to give download option to the user. The dialog box is comming but when i am saving it is giving me following error: "Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later." I am setting the following response header in the servlet. sponse.setContentType("application/xml"); response.setHeader("Content-Disposition", "attachment; filename=\"" + "filename.xml\"");
  2. RE: File Download from a servlet[ Go to top ]

    Your response headers look fine. Where are you copying your XML data into the response? It should look like this: //spring //org.springframework.util.FileCopyUtils String text = " "; //... ur code response.setContentLength(text.getBytes().length); FileCopyUtils.copy(text.getBytes(), response.getOutputStream()); //non-spring response.setContentLength(text.getBytes().length); //.. ur code ServletOutputStream sos = response.getOutputStream(); sos.write(text.getBytes()); sos.flush(); sos.close(); Hope this helps, K8
  3. See for example Download servlet in JSOS:
  4. Re: File Download from a servlet[ Go to top ]

    See this File download servlet example