0 Replies Latest reply on Jun 12, 2008 4:18 AM by jbal khadija

    Problem with enctype=\"multipart/form-data\" and File upload

    jbal khadija Newbie

      Hi all,
      I created a file uploading application using portlets.

      This is how it works...
      the jsp:

      <body>
      <form name="form1" method="post" action="<portlet:actionURL></portlet:actionURL>" enctype="multipart/form-data">
      
       <p>
       <input type="text" name="name">
      </p>
       <p>
       <input type="file" name="textfield2">
      </p>
       <p>
       <input type="submit" name="Submit2" value="Envoyer">
      </p>
      </form>
      </body>


      the portlet:

      public class PEssaiRecupereFichier extends GenericPortlet {
      public void processAction(ActionRequest request, ActionResponse response)throws PortletException, IOException {
      
      String name = request.getParameter("name");
      System.out.println( name);
      try {
       // Create a factory for disk-based file items
       FileItemFactory factory = new DiskFileItemFactory();
      
      // Create a new file upload handler
      PortletFileUpload upload = new FileeUpload(factory);
      // FileItem
      
       List items = upload.parseRequest(request);
       Iterator iter = items.iterator();
       while (iter.hasNext()) {
       FileItem item = (FileItem) iter.next();
       if (item.isFormField()) {
       String fieldName = item.getFieldName();
       } else {
       File fullFile = new File(item.getName());
      
       File savedFile = new File( "C://Documents and Settings/kjbal/Bureau/Dossiers",fullFile.getName());
       item.write(savedFile);
       }
       }
       } catch (Exception e) {
       System.err.println e);
       }
       }
      }


      The problem is that I am getting the uploading file fine...but I'm obtaining 'null' in the other parameter.

      I cannot figure out why.

      However, if I remove the enctype=\"multipart/form-data\" parameter from the form's tag, I can obtain the values of parameter perfectly, but i can't obtain the file upload.

      So, can any1 tell me what is the problem and how am I supposed to rectify it ?