Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
File Uploads in Java

Using HTTP

On the server

If you are using Servlets 3.0 or later, see the Servlet Specification for information on uploading files.

Servlet 2.x and JSP do not make any special provisions for multipart requests (file uploads), so when using Servlet 2.x and JSP, developers either have to depend on third party libraries or make their own framework.

Fabricating your own framework is incredibly difficult (multi-part requests are not trivial to parse) and would be re-inventing the wheel. Fortunately, there are several very good open source frameworks out there; with clear instructions and code examples.

The two most popular are Jakarta Commons FileUpload and

Note that request.getParameter() and its related methods do not work with multi-part requests, and will always return null when dealing with multipart form data.

On the client

If you want to upload files in conjunction with Commons HttpClient,
this introductory article tells how to use FileUpload in conjunction with the Commons HttpClient package.

Using FTP

It is possible to do basic FTP operations using J2SE:

To obtain a directory listing, simply create the URL with the directory you wish to index.

The Jakarta Commons Net package includes an FTP client which supports the full range of FTP commands.

Using SMB

The Samba project has a Java client library that can access Windows shares and Samba servers. Its API mimics the class, and is thus easy to use if you are familiar with File.

Using WebDAV

Tomcat ships with a WebDAV server component. The client side could be one of numerous available libraries, or the file managers of Mac OS X or Windows.

Back to the JspFaq ServletsFaq AppletsFaq
    Bookmark Topic Watch Topic
  • New Topic