Search code examples
javajspstruts

I have used write bean tag in jsp file but when i try to create output stream using response object then it gives IllegalStateException?


I have used write bean tag in jsp file but when i try to create output stream using response object then it gives IllegalStateException.

What is the solution to create output stream and run the code correctly.

Thanks in advance


Solution

  • The ServletReponse object provides two methods, getWriter to output text data, and getOutputStream to output binary data.

    Only one of them can be called, otherwise an IllegalStateException is thrown.

    In a JSP, the translated coded calls getWriter when needs to output any text, hence the error you are getting.

    To call response.getOutputStream in a JSP file you have to make sure that no text needs to be written prior to the call, so you have to get rid of all text outside the <% %> marks, even new line chars between JSP directives.