Question

There are two web applications. One is a client and other one is the provider. The provider is hosting a servlet to process a multipart file upload request. The client will upload the file to the provider servlet. The bottleneck is how to send a response back to the client. The client need to process according to the response send back by the provider. We cannot forward the request and response to a servlet/jsp because both the applications are in different servers. Then how to trap the response in the client side?

Was it helpful?

Solution

Just write to the response body.

response.setContentType("text/plain");
response.getWriter().write("OK");

You can even write XML or JSON so that parsing the response by the "client server" is easier.


Update as per the comment, the question is apparently poorly formulated and your actual problem lies elsewhere. It's not the response handling which is the problem, but the request handling. With JS/Ajax you cannot fire multipart/form-data requests. You've got to use Flash or a POST form in a hidden HTML iframe. You can find plethora of examples here. I personally recommend jQuery Form plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top