简体   繁体   English

使用Java处理HTML(多部分表单数据)文件上传

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

I'm working on a multiple file upload solution for a proof-of-concept web application. 我正在为概念验证Web应用程序开发多文件上传解决方案。 I'm using a java servlet to handle an AJAX file upload. 我正在使用Java Servlet处理AJAX文件上传。 My question is how does java handle uploading files from an HTML form? 我的问题是java如何处理从HTML表单上传文件? If someone could explain how a basic HTML file upload is processed then I could probably port this to my solution. 如果有人可以解释如何处理基本的HTML文件上传,那么我可以将其移植到我的解决方案中。

Quick tangent: I'm a web developer with a background in C# & PHP. 快速切线:我是一位具有C#和PHP背景的Web开发人员。 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. 我现在已经走上了一个新的职位,我的公司认为Java是所有编程语言的圣杯,我现在正试图跳上Java的潮流。 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. 我感觉好像在这里遗漏了一些东西……我绝对喜欢Java语言的感觉以及运行应用程序的容易程度。 But its seems infinitely difficult to use as a web programming language. 但是它似乎无限难以用作Web编程语言。

Thanks in advance. 提前致谢。

You can use Commons FileUpload library: 您可以使用Commons FileUpload库:

http://commons.apache.org/fileupload/ 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 http://commons.apache.org/fileupload/using.html

I just did it today. 我今天才做。 I followed this tutorial . 我遵循了本教程 It is specific for GWT , but author explained basics brilliantly. 它是GWT特有的,但作​​者精通了基础知识。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM