JSP使用SmartUpload上传文件

SmartUpload smart = new SmartUpload();
smart.initialize(config, request, response); //初始化文件上传
smart.upload();
     // 多个文件上传
for (int x = 0; x < smart.getFiles().getCount(); x ++) {
File currentFile = smart.getFiles().getFile(x); //获取文件后缀
currentFile.saveAs(application.getRealPath("/upload/") + UUID.randomUUID() + "." +  currentFile.getFileExt()); //修改文件名称,防止名称相同会导致文件被覆盖
}
----------------------------------------------------------------
// 单个文件上传
smart.save(文件保存目录);//在使用IDEA的时候文件保存目录需要注意,在out下。而不是源代码目录

  HTML FORM表单代码,需要注意加上 "enctype="multipart/form-data""

<form action="" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label for="dept_name">部门名称</label>
        <input type="text" class="form-control" id="dept_name" name="dept_name">
    </div>

    <div class="form-group">
        <label>部门图片</label>
        <input type="file" class="form-control" name="dept_image[]">
        <input type="file" class="form-control" name="dept_image[]">
        <input type="file" class="form-control" name="dept_image[]">
    </div>
    <button type="submit" class="btn btn-default">提交</button>
</form>

 

posted @ 2018-08-13 14:35  proxyInvocation  阅读(224)  评论(0)    收藏  举报