开发者

Redirecting after writing to response throwing exception

开发者 https://www.devze.com 2023-01-10 09:50 出处:网络
Am working on an application which has a requirement to download bulk data from a file server with a maximum开发者_StackOverflow中文版 file size constraint fixed at 3 Mb.It means i would have a maximu

Am working on an application which has a requirement to download bulk data from a file server with a maximum开发者_StackOverflow中文版 file size constraint fixed at 3 Mb.It means i would have a maximum download capacity of 3Mb.I am writing the input stream to the response output stream .My problem is I need to redirect my response to a jsp page after I downlaod.Now when I redirect using the code from my servlet..I get a java.lang.IllegalStateException: Cannot forward after response has been committed

RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/save.jsp");
rd.forward(request, response);

How can I redirect.Will downloading in a separate thread help me .Please advice ....


You cannot do it.

Basically, what "committed" means is that the server-side has started sending the response message to the client. At the very least, it has sent the first "line" of the response that contains the response status code. And if you want to do a redirect, that is implemented (in part) by setting a 3xx status code in the response.

You will have to figure out some way to do the redirect before the response gets committed.


You cannot redirect while the response has been already set. Further details here.

0

精彩评论

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