Forums Register Login

file processing on the servlet --urgent--

+Pie Number of slices to send: Send
hi.. i am building a servlet to read files sent by users using the http post method.. is there a way i can read and manipulate the file on the server without having to store it any place.. in short i wish to have an object instance of the file on the servlet which i can pass around to other servlets or applications to do diff types of processing on them
+Pie Number of slices to send: Send
If you receive the data into a byte[] or char[], you can create a ByteArrayInputStream or CharReader - If your other Java code is designed to read from one of these streams instead of being locked into requiring a file, you could avoid creating a file..
However, you might be better off using Java's temporary file capability - see java.io.File.createTempFile() and related methods.
Bill
+Pie Number of slices to send: Send
U can have the object stored in a common place, namely ServletContext. This will enable u to share the object between threads.
But then u have to make sure that this object is thread safe becoz if u use the setAttribute() nethod with a constant key, the Server will crash. Instead use a unique key (say e.g. hashCode of the object) and pass on this key as value in Request object.
Alternatively, u could pass on the data object using Request object. But if the size of the data object is considerable, then it will affect the performance of the Server on the whole.
Gopals.
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 815 times.
Similar Threads
XML+XSL with Java servlet
Loading a file in a servlet at run time
XML as servlet inputs
request.setParameter
Example: XML + XSL = HTML Using Servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:08:05.