標籤:cti elf var 沒有 支援 mod get val nal
很久沒有寫檔案上傳的代碼了,以下代碼支援非同步上傳,備忘一下。
1.版面設定
<div><input type="file" class="easyui-linkbutton" id="excelFile" name="excelFile" size="20" maxlength="20"/><input type="button" class="easyui-linkbutton" onClick="uploadFile();" style="width:80px" value="上傳" /></div>
2. js 代碼
function uploadFile() { var url = "upload.htm?method=upload‘)";var formData = new FormData();formData.append(‘excelFile‘, $(‘#excelFile‘)[0].files[0]);jQuery.ajax({ url: url, type: ‘POST‘, cache: false, data: formData, processData: false, contentType: false}).done(function(res) {console.log(res);}).fail(function(res) {console.log("failed="+res);}); } </
3. Action code
@RequestMapping(value="/upload.htm", params = "method=upload")public String upload(@RequestParam("excelFile") MultipartFile file, ModelMap model,HttpServletResponse response) { String fileName = file.getOriginalFilename(); InputStream is = file.getInputStream();}
ajax springMvc 非同步 上傳 檔案