• Post Reply Bookmark Topic Watch Topic
  • New Topic

IllegalStateException: Cannot Forward(Servlet 2.3, SRV 8.4)  RSS feed

 
Praveen Katti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am trying to forward to a jsp from my action handler using the following code, I am getting "java.lang.IllegalStateException: Cannot forward. Response already commited. (Servlet 2.3, SRV 8.4)" Exception. But the strange thing is its not coming in all the machines, some time it works, some time it does not.

My code is:
"request.getRequestDispatcher("AddRecord.jsp").forward( request, response );"
Help needed..

Thanks in advance,
Praveen

"request.getRequestDispatcher("AddRecord.jsp").forward( request, response );"
 
Rishi Tandon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check if u r writing to stream based on some conditions and then it is forwarding the request it is giving the Exception.

Paste the complete code so that we can have a look.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Translation:
u = you
r = are
Not everyone at JavaRanch has English as their first language. Please try to make posts easy to understand.

----

Some common causes of the problem you are seeing is when an Exception is thrown in an included part, or an included part is set as flush=true, or the buffer is filled.

As the previous posts says, it would be easiest if we saw a little more...
 
Praveen Katti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am attaching complete code

Thanks,

 
Ruchik Bhatt
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This exception could also because before the serlvet forwards the request, a part of the response is sent the to user.
 
Praveen Katti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Is it happens because of the Internet Explorer Version?, because on some of the machines it works fine where different version of Internet Explorer is running and in some it doesn't work because there is some other version. Advice Please

Thanks in Advance,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really already have your answer. Whether the exception is thrown or not depends upon whether there's been a buffer flush or not prior to the forward attempt. Your best bet is to re-structure your code such that any decision to forward or to redirect happens before any output is generated.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!