ho fatto una piccola prova con FileUpload di Jakarta Commons, non si sa mai mi ci trovassi a lavorare in futuro, prendendo paro paro il codice che c'è alla home page del progetto:
Una pagina con il form
codice:
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page - Upload Form</title>
</head>
<body>
<form name="uploadform" method="post" enctype="multipart/form-data" action="upload.jsp">
File: <input type="file" name="upload_file" />
<label>Un campo di testo</label><input type="textfield" name="text_field" />
<input type="submit" value="submit" />
</form>
</body>
</html>
e una landing page con la logica server-side, ricalcata in pieno dal sito
codice:
upload.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="org.apache.commons.fileupload.*,org.apache.commons.fileupload.servlet.*,org.apache.commons.fileupload.disk.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page - Landing Page Upload Form</title>
</head>
<body>
<h1>Fields</h1>
<%!
public String processFormField(FileItem item) {
String name = item.getFieldName();
String value = item.getString();
return (name+" "+value);
}
public String processUploadedFile(FileItem item) {
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();
String tot_info = "Field name: "+fieldName + "
" +
"File name: "+fileName+ "
" +
"Content type: " + contentType + "
" +
"Is in memory: " + isInMemory + "
" +
"Size (bytes): " + sizeInBytes;
return tot_info;
}
%>
<%
boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
if (isMultiPart) {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Set factory constraints
//factory.setSizeThreshold(yourMaxMemorySize);
//factory.setRepository(yourTempDirectory);
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Set overall request size constraint
//upload.setSizeMax(yourMaxRequestSize);
// Parse the request
java.util.List items = upload.parseRequest(request);
// Process the uploaded items
java.util.Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
out.println(processFormField(item)+"
");
}
else {
out.println(processUploadedFile(item));
}
}
}
%>
</body>
</html>
i due metodi dello scriplet come vedi non fanno niente di interessante, visto che era solo per provare, però come vedi i dati passano tutti.