在 Struts 2 中是否有可能获得下载文件(流)*和*重定向的结果? [英] Is it possible in Struts 2 to have a result that downloads a file (stream) *and* redirects?

查看:27
本文介绍了在 Struts 2 中是否有可能获得下载文件(流)*和*重定向的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下支柱定义:

<result name="reportSuccessfullyDownloaded" type="stream">
  <param name="contentType">application/zip</param>
  <param name="contentDisposition">attachment;filename="%{filename}"</param>
</result>

它会下载一个 .zip 文件,其中可以包含 1-10 个生成的 pdf 报告.

It downloads a .zip file that can contain anywhere from 1-10 generated pdf reports.

我想做的是更改应用程序以处理以下情况:

What I would like to do is change the app to handle the following situations:

  • 如果生成所有报告,请使用流"结果并下载.zip 文件.无需重定向.
  • 如果生成了一些报告但其他报告有错误,请使用流"结果并下载带有生成的 pdf 的 .zip 文件然后重定向到错误页面,其中报告不是生成的列表.
  • 如果没有生成报告,请跳过下载并重定向到列出了未生成的报告的错误页面.

我的问题是:如何为单个 Action 获得多个结果"?我不明白这怎么可能.是吗?或者我必须以某种方式必须使用链"结果,这是非常不鼓励的?

My question is: how can I have more than one "result" for a single Action? I don't see how it's possible. Is it? Or do I have to somehow have to use a "chain" result, which is highly discouraged?

非常感谢任何帮助.

推荐答案

我知道这已经很老了,但我建议您将报告生成的状态存储在会话中,并有一个服务于状态的 ajax 操作生成,以及另一个下载文件的操作.

I know this is very old already but I would suggest you to store the status of the report generation in session, and have an ajax action that serves the status of generation, and another action to download the file.

通过这种方式,您可以多次更新报告生成的状态并很好地提供它:

In that way, you can update the status of the report generation multiple times and serve it nicely like:

  • 一月 - 生成
  • 2 月 - 错误 #231,请联系支持人员
  • 三月 - 生成
  • 四月 - 进行中......
  • 五月 - 待定

一旦一切完成,您也可以自动开始下载.只需确保在用户重新进入页面或看起来合适时清除会话.

And once everything is done you can automatically start the download also. Just make sure to clear the session when the user re-enters the page or how ever seems appropriate.

这篇关于在 Struts 2 中是否有可能获得下载文件(流)*和*重定向的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆