简体   繁体   English

如何在 Servlet 上检索字符串作为 Multipart Post 的一部分发送

[英]How to retrieve String on Servlet send as a part of Multipart Post

This may be very simple question but I have been looking around for a while.这可能是一个非常简单的问题,但我已经环顾了一段时间。 I am sending two strings to a Java Servlet on Tomcat 7.我正在向 Tomcat 7 上的 Java Servlet 发送两个字符串。

multipartContent.addPart("destadd", sb1);
multipartContent.addPart("destfilename", sb2);

I am trying to retrieve these String like this我正在尝试像这样检索这些字符串

String destFileName = request.getPart("destfilename").getName();

but in vein.但在静脉中。 I will appreciate any help.我将不胜感激任何帮助。

I was running around for two days almost, fianlly I got the answer跑了快两天终于找到答案了

Part destFileNamePart = request.getPart("destfilename");
Scanner s = new Scanner(destFileNamePart.getInputStream());
String destFileName = s.nextLine();

有点晚了,但可能对其他人有帮助:

IOUtils.toString( destFileNamePart.getInputStream() );

Have you looked at Get form parameters from multipart request without getting the files .您是否查看过从多部分请求获取表单参数而不获取文件

You can also use utility class such as O'Reilly MultipartRequest and more info here您还可以在此处使用实用程序类,例如O'Reilly MultipartRequest和更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM