-4

In How to export data in CSV format using Java?, I found a solution to write the date to CSV files and the accepted answer works fine.

I need change file name to anything with .csv extention. Now I get WebServlet name as a file name without any extention.

Do you have any idea how to set a file name?

resp.setContentType("application/csv");
PrintWriter w = resp.getWriter();
w.println(generateCsvFile(policies));
w.flush();
w.close();
0

1 Answer 1

2

You need to set a file name to the header:

response.setHeader("Content-Disposition", "attachment; filename='" + filename + "'");

The browser will honor the header and use the file name for downloading file

Sign up to request clarification or add additional context in comments.

Comments

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.