This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
    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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis
  • Mark post as helpful
  • send pies
  • 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
com.oreilly.servlet

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 java.io.File 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
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!