Solved

IlligalstateException-output stream already in use

Posted on 2003-10-28
10
810 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Read about the ways of improving workplace communication.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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