Handling HTML (multipart form-data) file uploads with Java

血红的双手。 提交于 2020-01-01 19:15:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!