Solved

about ServletOutputStream

Posted on 2001-07-03
9
1,170 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
  • 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
 
LVL 2

Expert Comment

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

Best regards
Andrey
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 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

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 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

16 Experts available now in Live!

Get 1:1 Help Now