Hey all

I am trying to handle a JSP file upload with the Commons Fileupload api but
to no avail. The problem is that I never manage to parse the request coming
from my JSP
to my Servlet. Any ideas on what I might be doing wrong? There are no
exceptions thrown and I have the commons-io.jar in my web-inf/lib so I
should be all set. I've been dealing with this issue for over two days now,
any form of input is helpful!

Here's the Servlet method

protected void doPost(HttpServletRequest request,
           HttpServletResponse response) throws ServletException,
IOException {

       PrintWriter out = response.getWriter();

       DiskFileItemFactory factory = new DiskFileItemFactory();
       factory.setSizeThreshold(20000);
       factory.setRepository(new File(""));
       ServletFileUpload upload = new ServletFileUpload(factory);
       upload.setSizeMax(20000);
       File file = new File("/");

       try {
           List items = upload.parseRequest(request); //List never
populates :(

           Iterator iter = items.iterator();
           while(iter.hasNext()) {
               FileItem item = (FileItem) iter.next();
               item.write(file);
           }

       } catch(Exception e) {
           e.printStackTrace();
       }

   }

And the JSP HTML

<form action="FrontController" method="POST" enctype="multipart/form-data">
       <input type="file" value="filename" />
       <input type="submit" value="Submit" />
</form>

Reply via email to