I have a servlet newbie question. I have a servlet which gets a file name from a client and sends it the file. I would like to add a checksum feature so that the servlet can delete the file if it is sure that the client has received the file correctly. The client can compute a checksum when it writes the file. What is the best way to inform the servlet?
A "java.net.ProtocolException: Cannot write output after reading input" occurred in the client when I tried to send the checksum after reading the file. Do I have to use an entire different servlet to do this?
Thanks for the reponse. I'm a little confused about the keep-alive business. I looked up keep-alive connections and learned that I can keep the connection alive from the servlet by using ServletResponse.setContentLength(int) in the header. But it seems that I need to do this from the client: the client gets the file, computes a checksum, and now wants to inform the sending servlet of this checksum. What exactly do you mean by a "second cycle of request-response"? Do you mean something different than a keep-alive connection?
Originally posted by D Rog:
... I'd create something like transaction id for every file download. So, if a client consider download Ok, then a client issues another request to a servlet with a given transaction id, so a servlet can get it and delete a corresponding file...
Thanks for the response. Yes, I think the "stateless" part of http is the problem, here. I've decided to implement the deletion in a separate servlet. Note that the file name and a checksum together are already a transaction id, more or less. I'll have the server create a checksum file when the download happens, using CheckedOutputStream. The delete servlet can find files by name easily, and then use the checksum value to verify which file to delete.