簡體   English   中英

使用activeweb上傳文件的任何示例嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM