Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

Downloading file


In this example, we are going to download the jsp file. But you may download any file. For downloading the file from the server, you should specify the content type named APPLICATION/OCTET-STREAM.

index.jsp

This file provides a link to download the jsp file.

  1. <a href=“download.jsp”>download the jsp file</a>

download.jsp

In this example, we are downloading the file home.jsp which is located in the e: drive. You may change this location accordingly.

  1. <%
  2.   String filename = “home.jsp”;
  3.   String filepath = “e:\\”;
  4.   response.setContentType(“APPLICATION/OCTET-STREAM”);
  5.   response.setHeader(“Content-Disposition”,“attachment; filename=\”” + filename + “\””);
  6.   java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);
  7.   int i;
  8.   while ((i=fileInputStream.read()) != –1) {
  9.     out.write(i);
  10.   }
  11.   fileInputStream.close();
  12. %>

Comments

comments