开发者

Using Spring, how can I flush the output stream and also return the modelview?

I'm currently using Spring MVC.

What I'm looking to do is have a web page wh开发者_运维问答ere once the user submits a form, the controller writes a file to the output stream then flushes it, so the user may save the file. But I would then like the contoller to return a modelview, taking the user to another page.

At the moment once the output stream has been flushed, when the modelview get's returned, I end up with a "getOutputStream() has already been called for this response" error. (Normally I would return null after flushing the output stream to avoid this error).

So what I'm asking is, is there a way I can flush the output stream so the user can download the file and then return a modelview so the user is taken to another page?

Cheers.


I don't think what you're looking for is exactly possible, no matter what web framework you use. Best alternative I can think of is doing it the way Sourceforge.net processes downloads, e.g. a page with 'your download will start shortly', here's an example. (click the download link on the page)


You definitely can't redirect to a 2nd page if you've already begun writing to the output stream; this is part of the servlet spec rather than any one MVC framework

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜