Source Code:
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String pdf = req.getParameter("pdfurl");
String filename = pdf.substring(pdf.lastIndexOf("/")+1);
//res.setContentType("application/x-filler");
res.setContentType("application/pdf");
res.setHeader("Content-Disposition","attachment;filename=" + filename );
try{
FileInputStream fileInput = new FileInputStream(pdf);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStream = res.getOutputStream();
outStream.write(byteArray);
outStream.close();
}
catch(IOException ioe){
System.out.println("download:file input exception");//..........
//ioe.printStackTrace();
}
catch(Exception e){
System.out.println("download: exception");//..........
}
}