are you using "multipart" in your form declaration on the jsp page?

-----Original Message-----
From: Yann Verlynde [mailto:yverlynde@;oxade.com]
Sent: Monday, November 04, 2002 10:41 AM
To: Struts
Subject: Problem with FileUpload


Hello,

This is my code in an Action Class, I don't receive the upload file. The
fileItems element is null.
How can I do to upload a file?

Thanks in advance

public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {

   try {
      FileUpload fu = new FileUpload();
      // maximum size before a FileUploadException will be thrown
      fu.setSizeMax(1000000);
      // maximum size that will be stored in memory
      fu.setSizeThreshold(4096);
      // the location for saving data that is larger than getSizeThreshold()
      fu.setRepositoryPath("/tmp");

      List fileItems = fu.parseRequest(request);
      // assume we know there are two files. The first file is a small
      // text file, the second is unknown and is written to a file on
      // the server
      Iterator i = fileItems.iterator();
      String comment = ((FileItem)i.next()).getString();
      FileItem fi = (FileItem)i.next();

      // filename on the client
      String fileName = fi.getFieldName();
      // save comment and filename to database

      MessageResources messages =
(MessageResources)getServlet().getServletContext().getAttribute("APPLICATION
_CONFIGURATION");

      // write the file
      fi.write(messages.getMessage("upload.destination") + fileName);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    //return a forward to display.jsp
    return mapping.findForward("display");
}

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to