How to make an excel file (and txt file) filled with data from a table on the html page in a servlet and send it to a browser?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Firstly you need to generate the actual content (e.g. an Excel file). Apache POI can generate Excel spreadsheets easily. Alternatively you can simply generate a .csv file.
Secondly you need to return it with the correct content type. See this Javaworld tip for more info. Briefly, you set the content type on the response thus.
will set an Excel MIME type.
text/csvwould work if you generate a CSV file.You may also want to set the filename for downloading.
uses the
content-dispositionheader to achieve this.