I have an Html form with enctype="multipart/form-data"
. I have an dto
class it has all setter
and getters
. Since I am submitting form as multipart, getParameter()
method will not work,to process html form fields I used Apache Commons BeanUtils. My servlet is as follow,
List<FileItem> items = (List<FileItem>) new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
String fieldname = item.getFieldName();
String fieldvalue = item.getString();
System.out.println(fieldname);
System.out.println(fieldvalue);
// ... (do your job here)
//getters and setters
try {if((!fieldname.equals("dob"))&&(!fieldname.equals("doj"))){
BeanUtils.setProperty(teacherInfo, fieldname, fieldvalue);}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} else {
//Code for file upload
}
My problem is I am unable to process the date type variables , thats why I m ignoring to set two date values in above code and in above code for some html fields, value are not set by Beans setProperty() method . Can any one tell me where I am wrong . .