javascript
Brief description  about Online courses   join in Online courses
View Angandeep Kr Chatterjee 's Profile

a Servlet code to download a JAR file

I think this will involve handling the Reponse Stream in special manner that will be different from what we learnt in the course
Asked by Angandeep Kr Chatterjee | Jul 20, 2010 |  Reply now
Replies (1)
View Medha Vadi Saini 's Profile
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;
import java.lang.*;

public class MyServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

FileInputStream fileToDownload = new FileInputStream("c:/activation-1.1.1.jar");
ServletOutputStream output = response.getOutputStream();
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=activation-1.1.1.jar");
response.setContentLength(fileToDownload.available());
int c;
while ((c = fileToDownload.read()) != -1)
{
output.write(c);
}
output.flush();
output.close();
fileToDownload.close();


} //end doGet

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doGet(request,response);
}
}
Jan 3, 2011