It is not clear where you are reading your data from. You need to create an InputStream to read the data.
Then you first need to configure the response headers to
HttpServletResponse.setHeader("Content-Disposition", "attachment; filename=datafile.xls");
Use any file name you need.
Then set the mime type:
response.setContentType("application/vnd.ms-excel");
Use the desired mime type.
Then you need to use the response object to get its output stream -
OutputStream outStream = response.getOutputStream();
Now write to him:
byte[] buf = new byte[4096]; int len = -1;
source share