Solved

IlligalstateException-output stream already in use

Posted on 2003-10-28
10
808 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 137
maven project in eclipse 11 57
Set up Wildfly 10 8 356
maven webservice example issue 2 121
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 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

11 Experts available now in Live!

Get 1:1 Help Now