Question

Am working on an application which has a requirement to download bulk data from a file server with a maximum 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 ....

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top