File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getOutputStream() has already been called for this response

 
ramesh poorella
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me how to use JSTL here
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic