I have a Customer.jsp file on the server to send the content in an Excel file. I have kept the simple text "TestContent" to help me debug this.
<%
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=Test.xls");
%>
TestContent
When I download the file on the client side open, Excel(version 2013 or 2016) opens the file, but I get the following message:
The file format and extension of Test.xls don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?
I have also tried to set the header
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`
and file format as .xlsx
, but it also doesn't help because the warning still appears.
To address the duplicate notice, in the linked answer the author says to not use plain HTML tables with an application/vnd.ms-excel
content type. However, because I'm not using any html content, so how would that solution affect my situation (removing the warning)? I have padded all the request headers and content.
Also the target question asks
Is it possible under tomcat to just write a file as if it was a normal Java application [...] ?