Solved

IlligalstateException-output stream already in use

Posted on 2003-10-28
10
804 Views
Last Modified: 2010-05-18
I am calling response.getOutputStream() and initialing it as below in a jsp file.
  ServeletOutputStream sos=response.getOutputStream() ;
   ....
   ...
   sos.write();
   sos.flush();
   sos.close();
I commented out sos.flush() and sos.close() , but always it give that exception
at the end of the jsp page.

one more thing I am not calling response.getWriter().
and there is no out.write("\r\n"); in my jsp converted java file,sombody told like if out.write("\r\n"); will call the response.getwriter();
0
Comment
Question by:Subramanya
10 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9639417
why you will need to get the outputstream by your own??
in your jsp if there is even a single space somewhere in the  code you will get this exception...
the reason is that system uses the writer to write the output of jsp ( which is eventually total page - java sniplets)..
post your code here and I should be able to help you out with this.
0
 

Author Comment

by:Subramanya
ID: 9647559
The problem is solved after converting the Jsp into actual java servlet.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10747869
why I shd not be getting the points????
0
 
LVL 35

Expert Comment

by:girionis
ID: 10748262
Hello Kuldeepchaturvedi, I don't see you suggested the Servlet solution so I considered it better to PQ the question and refund the points. I can infer from your comment that your suggestion actually helped the asker.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 35

Expert Comment

by:girionis
ID: 10748265
sorry this

> I can infer from your comment

should be

I *cannot* infer from your comment
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10748277
>>>in your jsp if there is even a single space somewhere in the  code you will get this exception...
the reason is that system uses the writer to write the output of jsp ( which is eventually total page - java sniplets)..

is equivelent of either don't uses spaces in the jsp or don'y try to get outputstream because jsp will already have it in writer..
a way around this wd have been converting it to servlet....

which I agree that I didn't say explictly but in my opinion my comments was on the right direction..
but I honor your decision.
Thanks
0
 
LVL 35

Expert Comment

by:girionis
ID: 10748395
> s equivelent of either don't uses spaces in the jsp or don'y try to get outputstream because jsp will already have it in writer..

AFAIK spaces do not have anything to do with the problem but you are right on the second part of your latest comment, the implicit output stream is already obtained in the JSP. I would also have expected to indicate that the user could use the ServletOutputStream from the ServletResponse (response object) instead of the implicit JSP "out" variable.

Bare in mind that loads of people are not very experienced with Java (if they were they would ask a question that looks simple to most of us) and in order to have a better understanding of the mechanics you have to be explicit and sedulous.

Anyway, I do not want to be unfair here. My suggestion is just that, a suggestion, a moderator will decide on its final disposition. Therefore I will let a moderator decide and I am sure if (s)he finds your comment was helpful points will be awarded to you :)
0
 
LVL 35

Expert Comment

by:girionis
ID: 10748415
Soryr ignore that again:

>  I would also have expected to indicate that the user could use the ServletOutputStream from the ServletResponse (response object) instead of the implicit JSP "out" variable.

the user already obtains this stream (I think it's time for me to go to bed after so many hours in front of the computer)
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 10784969
PAQed, with points refunded (100)

CetusMOD
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now