【问题标题】:Sending a file over a request, so that the browser downloads the file通过请求发送文件,以便浏览器下载文件
【发布时间】:2016-08-21 06:17:19
【问题描述】:

我已经使用 FTL 模板成功生成了一个 XML 文件。感谢 Debmalya Biswas 和他的代码。

代码将文件(具有指定名称)保存到驱动器上的设置目录中。但我希望通过请求移交文件(对不起描述),以便浏览器将文件保存到其下载位置。你能帮忙吗?

<transition name="generateSEPAXML2">
    <actions>
        <script>
            <![CDATA[
                        import java.io.*

                        def screenRenderer = ec.screen.makeRender().rootScreen("component://SimpleScreens/screen/SimpleScreens/Accounting/Payment/PaymentSEPA.xml")
                                        .webappName("webroot").renderMode("csv")

                        String renderOutput = screenRenderer.render()

                        String fileName = "platba_" + paymentId + "_SEPA.xml"

                        Writer writer = new FileWriter(fileName)
                        writer.write(renderOutput)
                        writer.close()
            ]]>
        </script>
        <!--<service-call name="update#mantle.account.payment.Payment" in-map="[paymentId:paymentId, statusId:'PmntConfirmed']"/>-->
    </actions>

    <default-response url="."/>
</transition>

【问题讨论】:

    标签: moqui


    【解决方案1】:

    对于那些寻求答案的人来说,这对我有用:

        <transition name="generateSEPAXML3">
        <actions>
            <script>
                <![CDATA[
                            import java.io.*
    
                            def screenRenderer = ec.screen.makeRender().rootScreen("component://SimpleScreens/screen/SimpleScreens/Accounting/Payment/PaymentSEPA.xml")
                                            .webappName("webroot").renderMode("csv")
    
                            String renderOutput = screenRenderer.render()
                            ec.web.sendTextResponse(renderOutput, "text/xml", "platba_" + paymentId + "_SEPA.xml")
                ]]>
            </script>
            <!--<service-call name="update#mantle.account.payment.Payment" in-map="[paymentId:paymentId, statusId:'PmntConfirmed']"/>-->
        </actions>
    
        <default-response type="none"/>
    </transition>
    

    我使用了 ExecutionContext WebFacade 的 sendTextResponse 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多