You cannot do this in a JSP for exactly the reasons Paul mentioned. JSPs are solely inteneded to render character response data. Anything else, be it PDF, images or any other binary stream, must be emitted with a servlet.
create servlet file.
for example
setContentType(application/excel); but I think it depends on your browser.
also for pdf file setContentType(application/pdf);
open your pdf or excel file and read its content.