2

I'm working on a multiple file upload solution for a proof-of-concept web application. I'm using a java servlet to handle an AJAX file upload. My question is how does java handle uploading files from an HTML form? If someone could explain how a basic HTML file upload is processed then I could probably port this to my solution.

Quick tangent: I'm a web developer with a background in C# & PHP. I'm trying to hop on the Java bandwagon now that I've taken a new position where mycompany believes Java is the holy grail of all programming languages. I feel like I'm missing something here... I definitely like the feel of the Java language and how easy it is to run applications. But its seems infinitely difficult to use as a web programming language.

Thanks in advance.

4
  • 1
    There's an Apache project that's a library to do the MIME unpacking etc. It's an inherently messy problem for any server-side environment, but out of the Oracle box Java really doesn't do you any favors. (Really, Java as a web application language really only makes sense once you've picked one of the hundreds of frameworks to build on.) Commented Jan 28, 2011 at 21:16
  • Here is the project I was thinking about - personally I use it via the Stripes web framework, which adds its own layer of convenience over that. Commented Jan 28, 2011 at 21:20
  • Thanks Pointy. That's the project I was looking at a couple minutes ago too... being new to the Java scene, I wasn't sure what route to take yet. I'll check it out further. Commented Jan 28, 2011 at 21:25
  • Answer: stackoverflow.com/questions/2422468/… Commented Jan 29, 2011 at 0:02

2 Answers 2

3

You can use Commons FileUpload library:

http://commons.apache.org/fileupload/

Here is simple example of it's usage:

// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
List /* FileItem */ items = upload.parseRequest(request);

I taken this example from here:

http://commons.apache.org/fileupload/using.html

Sign up to request clarification or add additional context in comments.

Comments

1

I just did it today. I followed this tutorial. It is specific for GWT, but author explained basics brilliantly.

2 Comments

Nice tutorial. The author is using the same library that pointy suggested above. I'm going to give it a try. Many thanks!
Yes, apache commons are realy 'common' to use :) You'll definitelly write less boilerplate with these libs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.