当前位置: 首页 > 知识库问答 >
问题:

使用grails中的jasper插件在新选项卡中打开报表

邢卓
2023-03-14
 def index = {
        println(params)
        def testModel = this.getProperties().containsKey('chainModel') ? 
                       chainModel : null

        JasperReportDef report = null
        if (params.containsKey('auto_print_dialog')){

            report = docuJasperService.buildReportDefinition(params,
            request.getLocale(), testModel)
        }
        else{
            report = jasperService.buildReportDefinition(params, 
                     request.getLocale(), testModel)
        }
        generateResponse(report)
    }

    def generateResponse = {reportDef ->
        if (!reportDef.fileFormat.inline && !reportDef.parameters._inline) {
     //response.characterEncoding = "UTF-8"
      //response.setHeader("Content-disposition", 
      //"inline; filename=${params._name}");

          response.setHeader("Content-disposition", "inline; 
          filename="+(reportDef.parameters._name ?: reportDef.name) + 
                   "."+reportDef.fileFormat.extension);
            response.contentType = "application/pdf"
            response.outputStream << reportDef.contentStream.toByteArray()
        } else {

        render(text: reportDef.contentStream, contentType:
               reportDef.fileFormat.mimeTyp,
               encoding: reportDef.parameters.encoding ? 
               reportDef.parameters.encoding : 'UTF-8');

        }
    }

共有1个答案

羊舌阎宝
2023-03-14

这将由用于生成报告的链接处理。通常,添加_blank的目标就可以完成这个任务。例如:

<g:link controller="myReports" action="whateverReport" target="_blank">Click for your report</g:link>

这将打开一个新选项卡中的链接。

如果使用的是表单,向表单添加target将把表单提交到一个新的选项卡。例如:

<form name="myForm" action="whateverReport" method="POST" target="_blank">
<g:form name="myForm" controller="myReports" action="whateverReport" target="_blank">
 类似资料: