Answer the question
In order to leave comments, you need to log in
multipart/form-data java fields not coming?
Help solve the problem with getting data from Multipart/form-data of the form:
Form:
<form method="post" action="UploadServlet" enctype="multipart/form-data">
Select file to upload: <input type="file" name="uploadFile" >
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br/>
<input type="submit" value="Upload" />
</form>
try {
// parses the request's content to extract file data
List<FileItem> formItems = upload.parseRequest(request);
Iterator<FileItem> iter = formItems.iterator();
// iterates over form's fields
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
// processes only fields that are not form fields
if (!item.isFormField()) {
String fileName = new File(item.getName()).getName();
String filePath = uploadPath + File.separator + dateFormat.format(date) + fileName;
File storeFile = new File(filePath);
// saves the file on disk
item.write(storeFile);
String value = item.getString("firstname");
String value1 = item.getString("lastname");
}
}
Answer the question
In order to leave comments, you need to log in
If you add the @MultipartConfig annotation to the class and take parameters from the form like request.getParameter("firstname") at the beginning of the method, then everything seems to work. item.getString() - getString() takes as an argument an encoding, not a parameter name from the form.
Here in English they explain what's where
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question