Advertisement

07.21.2008 at 06:32AM PDT, ID: 23581713 | Points: 500
[x]
Attachment Details

multipart request + struts2 + aurigma uploader

Asked by Shoumitro in JDeveloper, Java Server Pages (JSP)

Tags: ,

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.util.*,
                         
                          org.apache.commons.fileupload.disk.*,
                          org.apache.commons.fileupload.FileItemIterator,
                          org.apache.commons.fileupload.servlet.*,
org.apache.commons.fileupload.servlet.ServletFileUpload,
                          org.apache.commons.fileupload.*              
                         %>

<%!

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(galleryPath);
absThumbnailsPath = context.getRealPath(galleryPath + "Thumbnails");
absTempPath = context.getRealPath(galleryPath + "Temp");
absThumbnailsPath = galleryPath + "Thumbnails";
absTempPath = galleryPath + "Temp";

//Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();

// Set factory constraints
factory.setSizeThreshold(4096);
factory.setRepository(new File(absTempPath));

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Set overall request size constraint
upload.setSizeMax(100000000);

//Parse the request
FileItemIterator iter = upload.getItemIterator(request);

//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.getFieldName(), 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(request);  does not return anything.
Please helpStart Free Trial
[+][-]07.21.2008 at 07:02AM PDT, ID: 22050554

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.21.2008 at 07:54AM PDT, ID: 22051052

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 05:12AM PDT, ID: 22058440

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 08:45AM PDT, ID: 22060639

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 10:14PM PDT, ID: 22066168

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 07:36AM PDT, ID: 22069734

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628