Is there some trick to getting a SpringMVC custom view to cause a file download in the broswer? I've implemented the render
method from org.springframework.web.servlet.View
but the code results in my data being written to the page as a blob of data rather having a download action start.
try {
Document oDoc = (Document) model.get("oDoc");
out = new PrintWriter(response.getOutputStream());
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment; filename=file.xls");
GenerateXLSFile gof = new GenerateXLSFile();
gof.outputTSVFromDom(out, oDoc);
} catch block here {
//writes to log here
} finally {
if (out != null) {
out.flush();
out.close();
}
}
I know the render method is being called from the server logs. I know the GenerateXLSFile is being created from the server logs. I know the outputTSVFromDom can take a document and transform it work from my JUnit test. It also writes to the server log and completes. The data ends up in the browser. The HTTP Headers looks normal according to firebug. No errors from the catch block are in the server log.
What am I missing here?