How to send multipart data and text data from HTML form to JSP page at time
my form field are Name ,upload file
I am unable to send both at a time
How to send multipart data and text data from HTML form to JSP page at time
my form field are Name ,upload file
I am unable to send both at a time
In a multipart/form-data
request, the text parameter is also sent as a multipart item, not as a regular query parameter. To get the text parameter, you need to use the same API as you have used to get the uploaded file. Assuming that you're using Apache Commons FileUpload, which is a de facto standard multipart/form-data
parser, then you need to hook on the condition where the item is a normal form field.
List<FileItem> items = 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();
// ... (do your job here)
} else {
// Process form file field (input type="file").
String fieldname = item.getFieldName();
String filename = FilenameUtils.getName(item.getName());
InputStream filecontent = item.getInputStream();
// ... (do your job here)
}
}