Reputation: 305
I have 2 normal text fields and 1 upload field to be parsed. The getFieldName();
as suggested in the Apache Tomcat FileUpload page seems to only get the name attribute of the input
html tag and not the parameter entered.
getRelDate = fi.getFieldName();
has the result of 'date'.
Also, if I use getFieldName()
for both of the normal text fields, they are of the same result.
How do I get the parameters of multiple normal text fields ?
The Html code:
<!-- 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>
The JSP code:
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>");
}
}
Upvotes: 0
Views: 675
Reputation: 160291
First, you're iterating over the form fields, and for each one, setting both getRelDate
and getApple
to the name of the field.
Second, you're setting field names, instead of field values.
Consider reading over the documentation for the libraries you try to use.
Nutshell is that if it's a simple form field, use getString()
to return field content.
If it's a file, there are a few options detailed in the link provided above.
Upvotes: 1