On Post方法PDF没有在Spring 3.0 Controller中下载

时间:2013-11-27 12:44:59

标签: java spring-mvc pdfbox

@RequestMapping(method = RequestMethod.POST, value = "/download/applicationpicker/{formName}", consumes = "application/json", produces = "application/pdf")
public void printInitialApplicationPDF(HttpServletResponse response, @PathVariable String formName, @RequestBody ArrayList uids) {

    String fileName = formName + ".pdf";
    response.setHeader("Content-disposition", "attachment; filename=" + fileName);
    ServletOutputStream out = null;
    FileInputStream in = null;
    try {
        downloadService.getApplicationPickerData(uids, "initial");
        in = new FileInputStream(ProductConstants.getDataFeedRoot() + ProductConstants.INITIAL_APP_FORM);
        out = response.getOutputStream();
        IOUtils.copy(in, out);
        out.flush();
    } catch (IOException ioe) {
        log.info("Error exporting file " + fileName);
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            log.info("Error Closing ServletOutputStream while wrting file " + fileName);
        }
    }

0 个答案:

没有答案