Newbie question on handling multipart rquest.
Using struts2, jdk1.5, aurigma uploader version 5.x
The index.jsp contains the applet to select the files. From index.jsp the selected files are submitted to upload.jsp
Code in upload.jsp
--------------------------
---------
<%@ page language='java'
import="java.io.*,java.uti
l.*,
org.apache.commons.fileupl
oad.disk.*
,
org.apache.commons.fileupl
oad.FileIt
emIterator
,
org.apache.commons.fileupl
oad.servle
t.*,
org.apache.commons.fileupl
oad.servle
t.ServletF
ileUpload,
org.apache.commons.fileupl
oad.*
%>
<%!
String galleryPath = "/gallery/";
String absGalleryPath;
String absThumbnailsPath;
String absTempPath;
String getSafeFileName(String fileName) {
String newFileName = fileName;
File file = new File(absGalleryPath + File.separator + newFileName);
int j = 1;
while (file.exists()) {
newFileName = j + "_" + fileName;
file = new File(absGalleryPath + File.separator + newFileName);
j = j + 1;
}
return newFileName;
}
private void deleteFiles(String path) {
File dir = new File(path);
String[] dirList = dir.list();
for (int i = 0; i < dirList.length; i++) {
File file = new File(path + File.separator + dirList[i]);
if (file.isFile()) {
file.delete();
}
}
}
%>
<%
//Process request.
ServletContext context = getServletContext();
absGalleryPath = context.getRealPath(galler
yPath);
absThumbnailsPath = context.getRealPath(galler
yPath + "Thumbnails");
absTempPath = context.getRealPath(galler
yPath + "Temp");
absThumbnailsPath = galleryPath + "Thumbnails";
absTempPath = galleryPath + "Temp";
//Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Set factory constraints
factory.setSizeThreshold(4
096);
factory.setRepository(new File(absTempPath));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory)
;
// Set overall request size constraint
upload.setSizeMax(10000000
0);
//Parse the request
FileItemIterator iter = upload.getItemIterator(req
uest);
//Put them in hash table for fast access.
Hashtable fileItems = new Hashtable();
if (iter!=null)
System.out.println("\n\n\n
is empty-----"+!iter.hasNext(
));
while (iter.hasNext()) {
FileItem fileItem = (FileItem)(iter.next());
fileItems.put(fileItem.get
FieldName(
), fileItem);
System.out.println("\n\n file name is "+fileItem.getName());
System.out.println("\n\n file size is "+fileItems.size());
}
%>
The result is:
The iterator is empty.
upload.getItemIterator(req
uest); does not return anything.
Please help
Start Free Trial