下载时如何从 servlet 向 Flex FileReference 发送错误消息
我使用 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.xml 中获取 servlet 错误消息吗?谢谢
I use fileReference.download() to download files. The fileReference send request to java servlet.In servlet, some error may be checked. For example error - 'File not found'. I want to send the error to flex side. I tried lots of methods,but fileReference in flex can't receive them.
Such as
response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
or
PrintWriter out = resp.getWriter(); out.print("File not found");
It seems fileReference can't triggers event 'DataEvent.UPLOAD_COMPLETE_DATA' and 'HTTPStatusEvent.HTTP_STATUS'.
Can somebody tell me how to get servlet error message in fileReference. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信 FileReference.download 调度 HttpStatus 事件,也不公开状态代码。
您只能监听 IOErrorEvent。
I do not believe FileReference.download dispatches a HttpStatus event, nor exposes status code.
You can only listen for IOErrorEvent.
认为没有解决办法。我努力尝试了几种方法,例如用 500 响应、用消息响应发送错误、返回 XML 文档(但您无法控制下载的内容)。我通过创建适合大多数情况的“全面错误消息”解决了这个问题(您没有权限或内容不可用...)
其他解决方案是使用 navigator 下载,但随后您需要打开浏览器窗口。
Think there is no solution. I tried hard several ways like responding with 500, sendError over response with message, returning XML document (but you don't have control over downloaded content). I solved the issue by creating a "allround error message" that fits to most situation (you have no permission or content is unavailable...)
Other solution is to download with navigateTo but then you need to open a browser window.