I am trying to download a csv file with the customized header and records in it. But i am not able to set header and fill the data in the csv file, but it does append the source code of the same view page. I want the csv file as following ouput.
empId EmpName Designation
101 John Programmer
102 Tom Manager
I am using the following code, it does not contain the code to write in the file. How can i achieve the expected output?
try {
response.reset();
response.setContentType(mimeType);
String headerKey = "Content-Disposition";
String fileName = "downloadEmployee.csv";
String headerValue = String.format("attachment; filename=\"%s\"", fileName);
response.setHeader(headerKey, headerValue);
} catch (Exception e) {
e.printStackTrace();
}