是否存在Java实用程序来生成HTTP多部分响应? [英] Is there a java utility to produce http multi-part responses?
问题描述
我正在构建一个返回多部分响应的Web服务.我知道构造多部分响应的格式;如果找不到现有工具,我将构建自己的工具.
I am building a web-service that returns a multipart response. I know the format for constructing a multi-part response; and I will build my own tools if I can't find existing tools.
也许我只需要有关Google-foo的帮助.我发现的所有内容都与发布或使用多部分消息有关.不会产生多部分响应.
Perhaps I just need help with my google-foo. Everything I find is about POSTing or consuming multi-part messages. Nothing about producing multi-part responses.
推荐答案
您可以使用oreilly servlets http://www.servlets.com /cos/
You can use oreilly servlets http://www.servlets.com/cos/
javadoc中有一个示例: http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartResponse.html
An example is in the javadoc: http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartResponse.html
import com.oreilly.servlet.MultipartResponse
//javax.servlet.http.HttpServletResponse res
MultipartResponse multi = new MultipartResponse(res);
multi.startResponse("text/plain");
out.println("On your mark");
multi.endResponse();
try { Thread.sleep(1000); } catch (InterruptedException e) { }
multi.startResponse("text/plain");
out.println("Get set");
multi.endResponse();
try { Thread.sleep(1000); } catch (InterruptedException e) { }
multi.startResponse("image/gif");
ServletUtils.returnFile(req.getRealPath("/images/go.gif"), out);
multi.finish();
这篇关于是否存在Java实用程序来生成HTTP多部分响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!