Wednesday, May 07, 2008

How to get the output (Report) in an Excel format with a "Save As" pop-up message

We set the below content type in the JSP page to produce the results of search query in excel sheet.
response.setContentType("application/vnd.ms-excel");

We add the below header in the JSP page to prompt a "Save As" dialog box to user on click of Export button.
response.addHeader("Content-Disposition", "attachment");


<%
response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment");
%%gt;