html 多部分表单中输入文本字段的值

问题描述:

我在一个带有字段的 html 表单的 java 服务器端应用程序中使用 Apache Commons FileUpload:

I use Apache Commons FileUpload in a java server-side app that has a html form with fields :

  1. 确定的目的地将是填写的电子邮件地址目标邮箱

  1. a destination fied that will be filled with email address of the destination mailbox

带有发件人消息的消息文本

a message text with a message of the sender

我猜您正在使用 FileItemIterator 来迭代请求中的项目.迭代器 next() 方法返回一个 FileItemStream(不是 FileItem).打开该对象上的流并将其转换为这样的字符串:

I am guessing you are using a FileItemIterator to iterate the items in the request. The iterators next() method returns a FileItemStream (not a FileItem). Open the stream on that object and turn it into a string like this:

import org.apache.commons.fileupload.util.Streams;
...
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
String name = item.getFieldName();
String value = Streams.asString(stream);

其他答案建议的getString方法是FileItem接口上的一个方法.

The getString method suggested by other answers is a method on the FileItem interface.