How to Upload Files with Apache Commons FileUpload

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public final class SampleServlet extends HttpServlet {

  protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException {

    try {
      final ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());

      final List<FileItem> itemList = upload.parseRequest(req);

    } catch (final Exception e) {
      throw new ServletException("Unable to receive files", e);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s