Before sending the file through Servlet, we need to set the response header which is done in the example below:

Java Code:
String filename = "abc.dat" ;
File textFile = new File(filename);
response.setHeader("Content-length",Integer.toString(textFile.length()));
response.setHeader("Content-type","application/octetstream");
response.setHeader("Content-disposition","inline; filename=" + filename );

// open the file and write it in the OutputStream