servlet之间的数据传递-使用POST方法
来源:互联网 发布:游戏模型提取软件 编辑:程序博客网 时间:2024/05/20 05:26
相关jar包:
commons-httpclient.jar
PostMethod post = new PostMethod(url);RequestEntity entity = new FileRequestEntity(inputFile, "text/xml; charset=ISO-8859-1");post.setRequestEntity(entity);HttpClient httpclient = new HttpClient();int result = httpclient.executeMethod(post);
用PostMethod 模拟http post请求,需要解决传递字符串,文件等需求。
httpclient对此,提供了对应实现,实现方法关键在:RequestEntity。
示例:
RequestEntity requestEntity = newStringRequestEntity(text); post.setRequestEntity(requestEntity);
示例中,是传递一个普通字符型参数。
这个方法代替了以前直接设置Request body。
RequestEntity是一个接口,有很多实现:
ByteArrayRequestEntity, FileRequestEntity, InputStreamRequestEntity, MultipartRequestEntity, StringRequestEntity
基本上从名字上就可以直接看出功能,可以从字符串,流,文件,字节数组中产生request body。
还有更复杂的Multipart,就是夹杂文件和普通字段的提交。
示例如下:
Part[] parts = {new StringPart("source", "695132533"), new StringPart("status", URLEncoder.encode(status, "utf-8")), filePart};postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
- servlet之间的数据传递-使用POST方法
- 使用 Post 方法传递数据
- Servlet之间传递数据
- Servlet(Action)之间的数据传递
- JSP、JAVASCRIPT、SERVLET之间数据的传递
- jsp与servlet之间的数据传递
- Servlet与JSP之间的数据传递
- JSP、servlet、SQL之间的数据传递
- jsp,servlet,sql之间的数据传递
- ThinkPHP与Angular使用POST方法传递数据的问题
- jsp中使用POST的方法在网页之间传递参数的简单方法
- AJAX的POST方法传递数据
- servlet 向 jsp传递数据的方法
- jsp接收servlet传递数据的方法
- 关于使用EL语句来接收servlet给jsp传递及jsp页面之间传递的数据
- C#窗口之间数据的传递 方法
- activity之间的数据传递方法
- WinForm窗体之间数据传递的方法
- 收集RAC诊断信息
- 【索引分类】位图连接索引
- android长度单位
- 问题四十四: f=1-i/2!+1/3!-...+1/9! (while循环)
- android 由data 获取联系人信息。
- servlet之间的数据传递-使用POST方法
- 优化C语言代码
- ooooookkkkkkkkkk 中文 yyyy
- cloudera cdh4 环境搭建
- 栈和堆的区别
- 集合 list set
- 使用Aspose.Pdf将PDF转换为JPEG图片格式
- linux环境变量设置方法总结(PATH/LD_LIBRARY_PATH)
- requestWindowFeature窗口风格设计