I am trying to post an Excel file to download from a servlet to a JSP. The content is written properly but to the IE browser and not in an Excel. I even tried giving the ContentType as Word/CSV etc. But nothing works, the content gets displayed only in the browser.
PLEASE HELP.
Code snippet in calling JSP:
DownloadServlet downServlet = new DownloadServlet();
downServlet.download(response);
Code in Servlet:
public class DownloadServlet extends HttpServlet{
public void download(HttpServletResponse response) throws IOException {
/PrintWriter out = response.getWriter( );
response.setContentType("text/html");
out.println("<H1>Hello from a Servlet</h2>"); /
/HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");/
String strData = "This is a Test for Download";
byte[] b = strData.getBytes();
//response.reset();
response.setHeader("Content-disposition", "attachment; filename=" + "Download.xls");
response.setContentType( "application/msword" );
//response.addHeader( "Content-Description", "Download Excel file" );
ServletOutputStream out = response.getOutputStream();
out.write(b);
//out.flush();
out.close();
}
}