如何处理来自servlet的jsp响应以进行多部分文件上载?(How to handle response in the jsp from a servlet for a multipart file upload?)

有两个Web应用程序。 一个是客户端,另一个是提供者。 提供程序托管一个servlet来处理多部分文件上载请求。 客户端将文件上载到提供者servlet。 瓶颈是如何将响应发送回客户端。 客户端需要根据提供商发回的响应进行处理。 我们无法将请求和响应转发到servlet / jsp,因为两个应用程序都在不同的服务器中。 那么如何在客户端捕获响应呢?

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?

最满意答案

只需写入响应正文。

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

您甚至可以编写XML或JSON,以便通过“客户端服务器”解析响应更加容易。


根据评论更新 ,问题显然很难制定,你的实际问题在其他地方。 这不是响应处理问题,而是请求处理。 使用JS / Ajax,您无法触发multipart / form-data请求。 您必须在隐藏的HTML iframe中使用Flash或POST表单。 你可以在这里找到大量的例子。 我个人推荐jQuery Form插件 。

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.

如何处理来自servlet的jsp响应以进行多部分文件上载?(How to handle response in the jsp from a servlet for a multipart file upload?)

有两个Web应用程序。 一个是客户端,另一个是提供者。 提供程序托管一个servlet来处理多部分文件上载请求。 客户端将文件上载到提供者servlet。 瓶颈是如何将响应发送回客户端。 客户端需要根据提供商发回的响应进行处理。 我们无法将请求和响应转发到servlet / jsp,因为两个应用程序都在不同的服务器中。 那么如何在客户端捕获响应呢?

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?

最满意答案

只需写入响应正文。

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

您甚至可以编写XML或JSON,以便通过“客户端服务器”解析响应更加容易。


根据评论更新 ,问题显然很难制定,你的实际问题在其他地方。 这不是响应处理问题,而是请求处理。 使用JS / Ajax,您无法触发multipart / form-data请求。 您必须在隐藏的HTML iframe中使用Flash或POST表单。 你可以在这里找到大量的例子。 我个人推荐jQuery Form插件 。

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.