Problem with forward : IllegalStateException

K

kinga

Hello,
I have a metod:

private void go_to(String adress, HttpServletRequest
request,HttpServletResponse response) throws ServletException, IOException{

RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(adress);
dispatcher.forward(request, response);
}

call her:

go_to("/result.jsp", request, response);


When I start application in IE throw me error:
'IllegalStateException: Cannot forward after response has been
committed'
In Netscape and Mozilla all work well.

Please, help!

Thanks for any answer,

Kinga
 
J

John C. Bollinger

kinga said:
Hello,
I have a metod:

private void go_to(String adress, HttpServletRequest
request,HttpServletResponse response) throws ServletException, IOException{

RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(adress);
dispatcher.forward(request, response);
}

call her:

go_to("/result.jsp", request, response);


When I start application in IE throw me error:
'IllegalStateException: Cannot forward after response has been
committed'
In Netscape and Mozilla all work well.

If you are using this inside a Servlet (or JSP), as it is intended to be
used, then the browser through which you access it has no direct
influence on its behavior. The exception message is fairly clear; the
only possible ambiguity I see is the definition of "committed", which in
this case is that the response is committed as soon as any response
bytes have been sent to the client (as opposed to being buffered on the
server). The behavior you observe is completely standard (and indeed,
required). You may be able to avoid it by increasing the response
buffer size (the means to do so depends on various factors, but by the
time you get to go_to() it is far too late), or, better, by ensuring
that your servlet / JSP produces less output before invoking go_to().

You may also want to make sure that you understand the semantics of
forwarding a request. In particular, it is important to recognize that
doing so discards any bytes previously written to the response. That's
/why/ you can't forward after the response has been committed. It may
be that what you want to do can be accomplished better by include()ing
the target resource, though that puts some restrictions on what the
included resource can do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top