• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Illegatstateexception !!!

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I understand that if I commit the response in some way by doing a write(), println() or a flush before I do the sendRedirect or RequestDispatcher forward, I will get an illegalstatexception.

But what happens if I try to write to the response in the forwarding servlet after the sendRedirect or RequestDispatcher method call.

Thanks !!!

Nishant
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have forwarded the request/response objects, so you have transferred control, and you should get an exception.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nishant,

I haven't tried that before but my guess is if you try somehow to write to the response after the forward call then nothing is going to happen (code not executed) since control will have been already transferred to the forwarded page.

Troy.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Let me try to explain the above case.

1. The servlet call the requestDispatche forward method. let the response is not committed so no problem.

2. After successfully executing the forward method. it will return to next line os the forward message.

3. Here the execution of the code in original servet resumes, but the response is committed so there is no way to display anything on the browser.

4. As you try to write somthing on the out, it throw the exception but can not show to the client as the response is already committed. But I can see the exception in server log.


Thanks
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic