Java文件上传

<%-- 上传文件的 jsp --%>

上传

/* 用ajax提交 /
KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲uploadBtn").cli…("#form")[0])
KaTeX parse error: Expected '}', got 'EOF' at end of input: …, url:"{pageContext.request.contextPath}/witkeyDemandScheme/addwitkeyDemandScheme",
data:fd
dataType:“json”,
processData:false,
contentType:false,
success:function (rs) {
var str=$("#showFiles").html();
if(rs.length>0){
for(var i=0;i /
拼接提交后的文件名 回显到页面 */
str+="

删除

"
}
}
$("#showFiles").html(str);
},
error:function (err) {
console.log(err);
}
})
});

/*Connection层 */
@ResponseBody
@RequestMapping("/addwitkeyDemandScheme")
public List addwitkeyDemandScheme(@RequestParam(“files”)MultipartFile[] files, String demandid, HttpSession session){
List list=new ArrayList();
WitkeyUser user = (WitkeyUser) session.getAttribute(“user”);
if(usernull){
return list;
}
if(files
null||files.length==0){
return list;
}
String realPath = session.getServletContext().getRealPath("/uploads/scheme");

for(int i=0;i1000000){
        list.add("该文件太大,无法上传");
        return  list;
    }
    String fileName=files[i].getOriginalFilename();
    fileName= saveNewFileName(fileName,demandid,user.getId());
    list.add(fileName);
    File f=new File(realPath+File.separator+fileName);

    try {
        files[i].transferTo(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
int i = witkeyDemandSchemeService.addwitkeyDemandScheme(demandid, user.getId(), list);
logger.debug("返回的数为:"+i);
return list;

}

你可能感兴趣的:(java文件上传)