浏览器下载代码

FileObject file = commandFactory.getDownloadFileCommand(fileobjectid).execute(credentialFacade);
            response.setContentType("application/x-download");

            String contentDisposition =  
                    FileUtils.encodeFilename(file.getFilename(), request) ;
            response.setHeader("Content-Disposition", "attachment;filename="+ contentDisposition);
            response.setHeader("Cache-Control", "max-age=1");
            response.setHeader("Pragma", "public");
            response.setHeader("Last-Modified", FastHttpDateFormat.formatDate(file.getCreationdate().getTimeInMillis(), null));
            response.setStatus(HttpServletResponse.SC_OK);
            fileActionFacade.writeFileToOutputStream(response.getOutputStream(), file);
            //20131113
            getAuditTrailFacade().logEvent(credentialFacade.getAccessUser().getDeptName(),credentialFacade.getAccessUser().getLogin(), file.getFile(), AuditTrailFacade.DOWNLOAD, "File downloaded - " + file.getFile().getNodeFullPath(), credentialFacade.getIpAddress());
            return file;

posted @ 2015-12-17 16:13  Nyan  阅读(374)  评论(0编辑  收藏  举报