[英]Any example of uploading files using activeweb?
我尝试将一些csv文件上传到服务器端并进行处理,然后保存到数据库,有关在activeweb中上传文件的任何示例?
Kitchensink示例包含一个上传演示: https : //github.com/javalite/kitchensink 。
这是可以处理多部分POST请求的代码示例:
public class UploadController extends AppController {
public void index() {}
@POST
public void save() throws IOException {
List<FormItem> items = multipartFormItems();
List<String> messages = new ArrayList<String>();
for (FormItem item : items) {
if(item.isFile()){
messages.add("Found file: " + item.getFileName() + " with size: " + Util.read(item.getInputStream()).length());
}else{
messages.add("Found field: " + item.getFieldName() + " with value: " + item.getStreamAsString());
}
}
flash("messages", messages);
redirect(UploadController.class);
}
}
在Freemarker方面:
<@form controller="upload" action="save" method="post" enctype="multipart/form-data">
Select a file to upload:<input type="file" name="file">
<input name="book" value="The Great Gatsby" type="text">
<button>Upload File</button>
</@>
我希望此代码易于理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.