0

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();
    }
2
  • Possible duplicate of Java servlet read a file and send it as response Commented May 14, 2019 at 14:20
  • my requirement is to download file with customised content suggest me except page view source how i can add my content to the page Commented May 14, 2019 at 14:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.