Monday 15 September 2014

jsp - Retrieve multiple form field parameters in a multipart enctype form -


I have to have 2 normal text fields and 1 upload field to be parsed. getFieldName (); As suggested, only the name attribute of the input html tag is not received and the parameter is not entered.

GetRelDate = fi.getFieldName (); The result of 'date' in is the result.

In addition, if I use getFieldName () for both common code, they are of the same result

HTML code

  & lt;! - Normal text field - & gt; & Lt; Td> Release date & lt; / Td> & Lt; Td> & Lt; Input type = 'text' size = 30 name = 'date' & gt; & Lt; / Td> & Lt; TD & gt; Apple & lt; / TD & gt; & Lt; Td> & Lt; Input type = 'text' size = 30 name = 'apple' & gt; & Lt; / Td> & Lt ;! - Upload field - & gt; & Lt; Td> Image Upload & lt; / Td> & Lt; Td> & Lt; Input type = 'file' size = 30 name = 'image file' & gt; & Lt; / Td>   

JSP code:

  string getRelDate = ""; String getApple = ""; Try to get the // // file item to parse the request list file items = uploads. Equality Request (request); // Process Iterator i = fileItems.iterator () on uploaded file items; While (i.hasNext ()) {FileItem fi = (FileItem) i.next (); If (fi.isFormField ()) {getRelDate = fi.getFieldName (); GetApple = fi.getFieldName (); } // Retrieve uploaded file parameters file2 = new file (filePath, fi.getName ()); Fi.write (make 2); Out.println ("Uploaded Filename:" + FilePath +++ Fi.getName () + "& lt; br & gt;"); }}    

First of all, you are repeating the form fields, and for each

Setting the second, both getRelDate and getApple to the field name. Second, you are setting the field value instead of the field name .

Consider.

In short, if it is a simple form, use getString () to return the field content.

If this is a file, then there are detailed options in the links given above.

No comments:

Post a Comment