I have in my form to receive a file and it does it well, but if I add inputs type text to the form, I no longer receive the file ...
I think the problem comes from this line
String contentType = request.getContentType();
Because it receives many different types and then it does not get into the if ... but I have no idea how to take a request.getParemeter (DEL file), in parentheses the name of this itself ... But when it comes to collecting it in the JSP so that it enters the ¿¿if ???
String textarea = request.getParameter("txtarea");
String origin = request.getParameter("txtorigin");
String topic = request.getParameter("txttopic");
String[] destination = request.getParameterValues("user[]");
//---------- Upload file to server
File file;
int maxFileSize = 5000 * 1024;
int maxMemSize = 5000 * 1024;
String filePath = "c:/apache-tomcat/webapps/data/";
String contentType = request.getContentType();
if ((contentType.indexOf("multipart/form-data") >= 0)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(maxMemSize);
factory.setRepository(new File("c:\temp"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(maxFileSize);
try {
List fileItems = upload.parseRequest(request);
Iterator i = fileItems.iterator();
out.println("<html>");
out.println("<body>");
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
if (!fi.isFormField()) {
String fieldName = fi.getFieldName();
String fileName = fi.getName();
boolean isInMemory = fi.isInMemory();
long sizeInBytes = fi.getSize();
file = new File(filePath + "yourFileName");
fi.write(file);
out.println("Uploaded Filename: " + filePath + fieldName + "<br>");
}
}
} catch (Exception ex) {
}
}// end upload file