0

在我的@RequestMapping POST 方法之一中,我需要返回 HttpServletResponse(这是一个 xml 文件)并且我想刷新视图。通常我只会返回路径,但在这种情况下,它会附加到用户正在下载的 xml 文件中。有没有办法先关闭并发送响应然后生成(刷新)视图?

4

1 回答 1

1

I would say no, it's not. Not a 100 percent sure though. You could try to send the file and also set the redirect header in your response. I didn't try it just now but I guess you will just be redirected. Really depends on the browser though. A browser could decide to still download the file.

Once you sent the response a new request needs to be generated by the client, so there is no way to close it server-side and just create a new one.

I would suggest a solution using Javascript. Either AJAX or just setting the current location twice (first the download, then the new view). I'm not sure, I guess via location.href

Let me know if you need an actual code example, as it would take me some time to manufacture something.

于 2012-04-24T10:37:07.410 回答