1 person found this helpful
That is not going to work in webcenter sites templates as you cannot change the content type like you do in standard jsp. The biggest pointer I've seen so far to do that is mentioned in this article:
Another option you have is to create a servlet that does the job for you, that is the one I've used. You can register the servlet inside the web.xml of the cs webapp.
I replaced this code :
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
whith this :
ics.StreamHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
it's working and I can download an excel file, but its content is not understandable,
it contais the content of the original file like if it was opened with notepad++ !
Is the content you are writing in UTF-8? Try specifying a charset. Also i think some versions of excel don't support even utf-8, may be try utf-16 in that case.
If the content you are trying to serve (file.xls) is actually contained within an asset, for example as a blob attribute of an asset, then you can use the blobserver tags in a Sites JSP to generate a url to it, and at the same time instruct any custom headers to be sent, including Content-Type & Content-Disposition
see the tag reference for render:getbloburl - http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/render-getbloburl.html
If the content you are trying to serve is not contained within an asset and really is coming directly off the disk then you may be better off serving it direct from the webserver, and let that take care of the content headers. Or failing that, write a small custom servlet as Pedro suggested.