Birt报告未以PDF格式打开

时间:2011-05-04 03:51:02

标签: ajax spring birt

大家好          我将表单值发送到控制器和控制器到rptdesign文件我正在生成具有适当值的临时文件夹中的报告但我的要求是它应该用户保存或打开对话框以便用户可以保存报告或打开          我认为ajax请求不允许下载任何文件,所以如果有人知道更好的解决方案PLZ回复

我的控制器在

之下
@RequestMapping("/leave/generateEmpLeaveReport.json")
public void generateEmployeeLeaveReport(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String reportName = "D:/git-repositories/cougar_leave/src/java/com//report/myLeaveSummary.rptdesign";
    File designTemplateFile = new File(reportName);
    if (!designTemplateFile.exists()) {
        throw new FileNotFoundException(reportName);
    }

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("empId", NumberUtils.toInt(request.getParameter("id")));
    parameters.put("reportTitle", "EMPLOYEE LEAVE");
    parameters.put("fromDate", request.getParameter("fromDate"));
    parameters.put("toDate", request.getParameter("toDate"));
    parameters.put("leaveType",
            NumberUtils.toInt(request.getParameter("leaveType")));
    parameters.put("transactionType",
            NumberUtils.toInt(request.getParameter("transactionType")));
    reportManager.addSystemParams(parameters, null,
            RequestUtils.getUser(request));
    File file = null;
    try {
        ReportType reportType = ReportType.PDF;
        OfflineReportContext reportContext = new OfflineReportContext(
                reportName, reportType, parameters, null,
                "EMPLOYEE LEAVE SUMMARY");

        StringBuffer buffer = new StringBuffer();
        file = offlineReportGenerator.generateReportFile(reportContext,
                buffer);
        ControllerUtils
                .openFile(file.getParent(), response, file.getName());
    } catch (Exception e) {
        log.error(e, e);
    } finally {
        if (file != null && file.exists()) {
            file.canExecute(); 
        }
    }

}

我的ajax请求在

之下
generateReport : function() {
        if (this.form.valid()) {
            fromDate = new Date($("input[name='fromDate']").val())
            toDate = new Date($("input[name='toDate']").val())
            if (fromDate > toDate) {
                GtsJQuery
                        .showError("To date should be greater or equals than From date !")
            } else {

                var request = GtsJQuery.ajax3(GtsJQuery.getContextPath()
                                + '/leave/generateEmpLeaveReport.json', {
                            data : {
                                id : $("input[name='employeeId']").val(),
                                fromDate : $("input[name='fromDate']")
                                        .val(),
                                toDate : $("input[name='toDate']").val(),
                                leaveType : $("select[name='leaveType']")
                                        .val(),
                                transactionType : $("select[name='transactionType']")
                                        .val(),
                                orderBy : $("select[name='orderBy']").val()
                            }
                        });
                request.success(this.callback("onSubscribeSuccess"))
            }
        }
    },

1 个答案:

答案 0 :(得分:0)

控制器响应应该是临时文件本身,只需调整内容类型。