• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with OutputStream

 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to the JSP's and this problem is troubling me a lot.
I have a JSP page. from this page, I access a Java class(this is basically a part of custom tag lib) in which I use JspWriter to print the data and from this java class, I call a function of another java class. Here I am supposed to send data to the browser as an extension to the taglib class data.
The flow is something like this:
1. I have some data in the JSP page.
2. I use a tag from custom tags, so i reach a java class, manipulate and send some data through JspWriter.
3. From this tag librabry class, i call a function of another java class sending request and response objects as parameters. in this class, i have to push some more data.(I get the problem here)
4. Control is back to taglib class. add few more JspWriter.print statements.
5. Control is back to JSP. I mean I get the JSP page refreshed back with all this data.
while thru this flow, when I try to use getOutputStream() of response object in the function call, I am getting an error which says this outputstream has already been called.
so how do I send the data to the outputstream from this class? I don't understand how to do this. Please help me.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Lavanya N!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper namesare required. In particular, you cannot use an initial for your last name. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Fourm Bartender
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now as to your question...
It sounds to me like you have too many fingers sticking into the JSP pie. What I tend to do, rather than having every class and its brother trying to emit output to the JSP stream, is to aggregate the output data into a StringBuffer and then, under the control of the custom tag code, emit the flattened buffer to the output stream at the appropriate time.
This also helps to decouple your utility classes from the servlet engine. Always a useful thing.
bear
[ October 12, 2003: Message edited by: Bear Bibeault ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very close to what I was thinking.
My take was that by passing the request and response objects around, you're making coding easier for yourself, but you're giving the external parts too much control and too much knwledge of your system.
If the externalo system needs to supply text data, only give it what it needs and make it give a String back. Hide the rest of the data on the request, and hide the fact that it is servlet based completely.
Dave.
 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand this but my problem is that the return type of the java function is uncertain. it can return a string or an image. so, i want to push the data from the java class file making the function return type void. But i get the problem with outputstream as it was opened already in the tag class. Now, what should I do?
Lavanya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!