I have a jsp page which displays a report run from my db as an excel document in the clients browser.
Unfortunately some reports have really huge results sets which make viewing in the browser not a good option because of the long wait time. I would instead like to send this excel document as a file to the client and force the browser to display the save dialog box.
All help is appreciated thnx.
This depends on whether you want to save a copy of the file on your server as well.
If yes then
1. fetch the resultset
2. Convert to excel format
3. save it as an Excel file on the server
4. then read the file in your servlet and send it in the response
if no then
carry out steps 1 & 2 as it is.
3. get the file as a large string object and send it to a jsp.
4. in jsp set the headers to denote the type of information and write the string in the body.
you could use POI for generating the excel file but it would be a very slow operation and would consume huge amount of resources for large datasets.
Follow this approach only if needed otherwise you can display large resultsets using paging.
One crude way can be - give the file extension of the reslt file as some unknown vague one which is not recognised by the browsers. In that case if it si not bale to recognise the file extension then the browser will bring up the save or open dialog box.
You can also ensure that the Open/Save dialog box appears every time by setting the response header with the value
"Content-disposition: attachment; filename=fname.ext"