To make the browser download file (several browser has supported default pdf viewer in their engine), simply add thisattribute to HtttpServletRespones :

Agar browser dapat mengunduh file tambahkan attribute di bawah ini :

uncomment this line to make browser download the file
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=xxx.fileExtension");

if you get error servlet ouput stream that already called, you can use this trick, simply reset the response when your menu view get called.

response.reset();

this error caused because the codes using response.getOutputStream().write(Object). when we using JSP the component that responsible for rendering JSP as HTML in browser is servlet.write using output stream resources.

so when we redirect to another view (example in spring mvc : return string_page.jsp) it will conflict the resources. because we already define the resource to write in byte

Updated :

In jasper report 6.xx version the xlsxExporter.setParameter is deprecated, so instead define jasper parameter we can define the configuration using jasper configuration :