Solved

about ServletOutputStream

Posted on 2001-07-03
9
1,173 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven module vs maven project 3 68
Html Table Looping (part 2) 5 34
Delphi Firemonkey: if the Sms contain special characters it won't send it 3 62
Setup GlassFish 4 34
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

685 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