Solved

about ServletOutputStream

Posted on 2001-07-03
9
1,175 Views
Last Modified: 2008-02-07
in my servlet i am writing some data on SetvletOutputStream.Before reaching to the client i want to modify some data which i wrote on outputstream.How i can read the data from ServletOutputStream and manipulate it??
0
Comment
Question by:manojvelliyatt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:Prasanna_Hebbar
ID: 6251437
Can't you modify the data before writing into ServletOutputStream and then write it into output stream?

If that is not possible, the other solution will be to do write another servlet. This servlet gets the result from the main servlet and modifies the data and writes the data into its output stream. The client program now instead of using the main servlet, use this secondary servlet.

Again can you be more clear on your intent? Instead of going for the above approach, where there is one more layer, there might be a simple and cleaner solution. Like you can write a class at the client side to modify the data.

More explanation please.....
0
 
LVL 2

Expert Comment

by:Andrey_Kulik
ID: 6252563
Hi
in your case you could create ProxyOutputStream. This Stream will flush their content to the real ServletOutputStream after all changes during work with data.

Andrey
0
 
LVL 4

Accepted Solution

by:
omry_y earned 200 total points
ID: 6253075
just write your output to a ByteArrayOutputStream insead of to the ServletOutputStream, get the bytes array, manipulate it(you can read it easly using ByteArrayInputStream), and than write the resulting byte array to the ServletOutputStream.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 2

Expert Comment

by:Andrey_Kulik
ID: 6253179
omry_y : it's the same :)

Best regards
Andrey
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6253208
well, not exactly.
you can`t really manipulate stuff inside an output stream.
(not even a proxy output stream).
you will to get the data in another form, either a byte array, or an input stream.

0
 

Author Comment

by:manojvelliyatt
ID: 6254188
omry_y,
how i can convet my ServletOutputStream to ByteArrayOutputStream i don't think that is possible.it will throw a class cast exception at run time.
just check it out and tell me the result.

Andrey_Kulik,
what is this ProxyOutputStream?
do you mean i have to write a proxy server,and communicate to my servlet.

0
 
LVL 2

Expert Comment

by:Prasanna_Hebbar
ID: 6254301
manoj,

Whatever omry_y has suggested is the change in the servlet. Instead of writing the data into servlet output stream, he is suggesting you to write the data into a bytearrayoutputstream. Then modify the data from bytearrayoutputstream and write it into servlet output stream.

This is much similar to what I suggested. ie modify the data before writing the data into servlet. I don't think you need to have bytearrayoutputstream if you are ready to modify the data in the servlet. Why you should write the data into a bytearrayoutputstream, instead you can store the data in a string. Modify this string, and latter write it into servlet output stream.

Again, can you be more clear on your question? Are you ready to modify the code in the servlet? Or do you want to put one more layer?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9017937
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to Prasanna_Hebbar]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0
 
LVL 4

Expert Comment

by:omry_y
ID: 9018346
I think Prasanna_Hebbar and I both suggested valid solutions.
mine means changing the code, but leaving the configuration the same.
Prasanna_Hebbar means leaving the code the same, but changing the configuration.

I therefor think the points should be splited between us.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

729 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