• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalStateException

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting the below exception whenever I forward the control to a new JSp from servlet.
Please suggest a solution.

java.lang.IllegalStateException: Cannot forward request if ServletOutputStream or PrintWriter has already been obtained

This is coming whenever I try to forward the request to a new page although its not hampering the flow of the application.

Is it due to the use of request dispatcher?

Please help me out!

Aashu
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ashutosh Arya wrote:I am getting the below exception whenever I forward the control to a new JSp from servlet.
Please suggest a solution.

java.lang.IllegalStateException: Cannot forward request if ServletOutputStream or PrintWriter has already been obtained

This is coming whenever I try to forward the request to a new page although its not hampering the flow of the application.

Is it due to the use of request dispatcher?


Can you post that code snippet here? It would be easier to see what's wrong.
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means you're probably doing a lot of things in your JSP that you should not be. It's very rare to need to forward from a JSP. That you are trying to do so may indicate a design flaw.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to decide at the top of the page before anything is started to be printed whether to redirect.
However, I believe that just like with tag classes , with JSP scriptlet or JSTL you can cancel page processing, then redirect, but that may be the same clause(meaning you could have processed a large portion of the page but not sent it).
Look through the <@page > directives for buffer , and i think one directive has an attribute output whether to be "verbose"(output as it occurs) also.
If you need to do that after print, you could cease at an appropriate element and print a javascript with
<script>
window.location="http://mysite/thepage.jsp";
</script>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic