The best practice for getting HTML form fields in Servlet is to use apache commons-fileupload 1.3 jar.
Using the iteration iterator through multipart HTTPServletRequest and use the for loop to check if it is FormField (), then
String item1=null,item2=null,item3=null; if(item.isFormField()) { if(item.getFieldName().equals("field1")) { item1=item.getString(); } if(item.getFieldName().equals("field2")) { item2=item.getString(); } if(item.getFieldName().equals("field3")) { item3=item.getString(); } }
and your HTML file should look like this
<html> <body> <form action="servletname" method="post" enctype="multipart/form-data"> <input type="text" name="field1"> <input type="text" name="field2"> <input type="text" name="field3"> <input type="file" name="filetoupload"> <input type="submit" value="Upload"> </form> </body> </html>
Cobweb
source share