aspose file tools*
The moose likes JSP and the fly likes getOutputStream() has already been called for this response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "getOutputStream() has already been called for this response" Watch "getOutputStream() has already been called for this response" New topic
Author

getOutputStream() has already been called for this response

ramesh poorella
Ranch Hand

Joined: Jul 19, 2011
Posts: 59
hi



when i am excuting that code that will given getOutputStream() has already been called for this response exception..

and html code not executed please help me
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

The time to be putting Java code into a JSP has long since passed. It has been almost 10 years since scriptlets have been discredited and replaced with the JSTL and EL.

Do you not think it is high time to catch up?

This sort of error is avoided when you follow best practices.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

And, if you insist on following poor practices, you should never obtain the output stream in a JSP. An implicit variable is already available.
ramesh poorella
Ranch Hand

Joined: Jul 19, 2011
Posts: 59
please help me how to use JSTL here
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

You'll need to find yourself a good modern tutorial or book that focuses on the JSTL. It's a big, but vitally important, concept to understand.

The JSTL and the EL are the way to add dynamic elements to a JSP -- not Java scriptlets.

An essential part of making it possible to use the JSTL and EL effectively is to have the web app properly structured with controllers; this article can help to get you started there.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

All of what Bear says is very true. However if I understand that page correctly, it starts out by saying "The contents of this response will be a GIF image".

And then it goes on to output some HTML code. This doesn't make sense: GIF images don't contain HTML.

After that it switches to Java and copies the contents of a JPEG image to the response. This doesn't make sense: a JPEG image isn't a GIF image, and you can't embed images into HTML either.

And finally you go back to HTML and output a link to a PNG image. Not a GIF or a JPEG image, but a PNG image.

All I can say is that the code contains a number of basic misunderstandings beyond the misguided decision to use Java scriptlets in a JSP.
Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31
Hi Ramesh,

As Bear and Paul mentioned you would need refractor your code pretty much.

For every http request,
- the servlet container creates a request and response objects.
- your servlet uses the data in the request to process
- it sets back necessary data in the response object
- the Servlet container based on your page forward responds back as a jsp

At this last step when the response leaves your container, your outputstream will be committed and you cannot modify it later.
Here you are trying to modify the committed response in your result jsp which will throw you a response saying outputstream is already committed



Thanks and Regards,
Sathiesh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getOutputStream() has already been called for this response
 
Similar Threads
Generating PDF from jsp using iText
JSP to Display PDF ?
displaying a image in a JSP
Server Program - Responding To Post Requests From HTML pg.
java.lang.IllegalStateException: getOutputStream() has already been called for this response