Problem with forward : IllegalStateException

Discussion in 'Java' started by kinga, May 19, 2005.

  1. kinga

    kinga Guest

    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
    kinga, May 19, 2005
    #1
    1. Advertising

  2. kinga wrote:

    > 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.

    --
    John Bollinger
    John C. Bollinger, May 19, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Duane Morin
    Replies:
    2
    Views:
    881
    John C. Bollinger
    Jul 24, 2003
  2. Replies:
    9
    Views:
    30,214
    sameer.rede
    Sep 4, 2007
  3. qazmlp
    Replies:
    1
    Views:
    582
    Jonathan Turkanis
    Feb 15, 2004
  4. Jan van Mansum
    Replies:
    0
    Views:
    457
    Jan van Mansum
    Jul 23, 2006
  5. ptreves
    Replies:
    3
    Views:
    268
Loading...

Share This Page