我尝试将一些csv文件上传到服务器端,并对它们进行处理并保存到数据库中,有没有在activeweb中上传文件的例子?
发布于 2019-01-16 23:22:41
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>
</@>我希望这段代码很容易理解。
https://stackoverflow.com/questions/54202881
复制相似问题