问题
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.
回答1:
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
回答2:
I just did it today. I followed this tutorial. It is specific for GWT, but author explained basics brilliantly.
来源:https://stackoverflow.com/questions/4833108/handling-html-multipart-form-data-file-uploads-with-java