Hello there, i've browsed the forum a lot about this problem, but couldn't find any clear solution:
I'm trying to download a file (not showing it) directly from a oracle database by clicking on a link in a page managed by a child class of SimpleFormController.
Here is the code i use to pass the file to the jsp:
Two problems arise:Code:protected ModelAndView processFormSubmission( final HttpServletRequest request, final HttpServletResponse response, final Object command, final BindException errors) throws Exception { //Retreives the id sent by the jsp after clicking on the link to download Long fileToDownloadId = RequestUtils.getLongParameter(request, "download"); if(fileToDownloadId != null && fileToDownloadId .longValue() > 0){ //retreives the image object containing the file MyImageObject obj = mySecurityManager.getMyImageObject(); String filename = obj.getFileName(); byte[] fileBytes = obj.getFileBytes(); response.setContentType("application/cer"); response.setHeader("Content-Disposition","attachment; filename=\""+filename +"\""); ServletOutputStream outs = response.getOutputStream() outs.write(fileBytes); outs.flush(); outs.close(); return showForm(request, response, errors); } //more code }
1) I manage to fetch the file as a byte array just fine, and after clicking on the link, i do have a download popup appearing, however I'm downloading the entire html page in addition of the file's content! The downloaded file starts with the data of the file fetched in db, followed by the html page's data.
2) In IE only, the name of the downloaded file is the the name of the page (myJsp.do instead of myFilename.cer).
I'd like of course to get the fetched file's data only.


Reply With Quote