我有 2 个普通文本字段和 1 个要解析的上传字段。getFieldName();
正如Apache Tomcat FileUpload 页面中所建议的那样, 似乎只获取了input
html 标记的名称属性,而不是输入的参数。
getRelDate = fi.getFieldName();
有“日期”的结果。
此外,如果我getFieldName()
对两个普通文本字段都使用,它们的结果相同。
如何获取多个普通文本字段的参数?
html代码:
<!-- normal text fields -->
<td>Release Date</td>
<td><input type='text' size=30 name='date'></td>
<td>Apple</td>
<td><input type='text' size=30 name='apple'></td>
<!-- upload field -->
<td>Image Upload</td>
<td><input type='file' size=30 name='imagefile'></td>
JSP 代码:
String getRelDate = "";
String getApple = "";
try{
// Parse the request to get file items.
List fileItems = upload.parseRequest(request);
// Process the uploaded file items
Iterator i = fileItems.iterator();
while ( i.hasNext () )
{
FileItem fi = (FileItem)i.next();
if ( fi.isFormField () ){
getRelDate = fi.getFieldName();
getApple = fi.getFieldName();
}
// Get the uploaded file parameters
File file2 = new File(filePath,fi.getName());
fi.write(file2);
out.println("Uploaded Filename: " + filePath + fi.getName() + "<br>");
}
}