我有一个 multipart/form-data 表单,其中包含文件上传部分和其他字段,例如复选框。我想根据复选框中的信息创建一个字符串,用“;”分隔 以便将其发送到数据库。
我的 UploadServlet 看起来像这样:
try {
// parses the request's content to extract file data
List formItems = upload.parseRequest(request);
Iterator iter = formItems.iterator();
// iterates over form's fields
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
// processes only fields that are not form fields
if (!item.isFormField()) {
//doSomething
String fileName = new File(item.getName()).getName();
String filePath = uploadPath + File.separator + fileName;
File storeFile = new File(filePath);
// saves the file on disk
item.write(storeFile);
}
else
{
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
String fieldname = item.getFieldName();
String fieldvalue = item.getString();
// Do anotherThing
// Can I create a string from the checkbox inputs here?
}
谢谢!