【问题标题】:How to send error message from servlet to flex FileReference in Flex When download下载时如何将错误消息从 servlet 发送到 Flex 中的 flex FileReference
【发布时间】:2011-10-08 10:29:23
【问题描述】:

我使用 fileReference.download() 来下载文件。 fileReference 向 java servlet 发送请求。在 servlet 中,可能会检查一些错误。例如错误 - “找不到文件”。我想将错误发送到 flex 端。我尝试了很多方法,但是 flex 中的 fileReference 无法接收它们。 比如

response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");

PrintWriter out = resp.getWriter(); out.print("File not found");

似乎 fileReference 无法触发事件“DataEvent.UPLOAD_COMPLETE_DATA”和“HTTPStatusEvent.HTTP_STATUS”。 有人可以告诉我如何在 fileReference 中获取 servlet 错误消息。谢谢

【问题讨论】:

  • 我不知道你在问什么。请简明扼要,否则此问题将被关闭。

标签: apache-flex servlets download filereference


【解决方案1】:

我不相信 FileReference.download 调度 HttpStatus 事件,也不会暴露状态代码。

你只能监听 IOErrorEvent。

【讨论】:

  • 我已经听过 IOErrorEvent。但错误消息类似于“#2038”。我想得到一些有用的消息,比如我发送的消息 response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
【解决方案2】:

认为没有解决办法。我尝试了几种方法,例如使用 500 响应、使用消息响应 sendError、返回 XML 文档(但您无法控制下载的内容)。我通过创建适合大多数情况的“全方位错误消息”解决了这个问题(您没有权限或内容不可用......)

其他解决方案是使用 navigateTo 下载,但您需要打开浏览器窗口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    相关资源
    最近更新 更多