easyui ajax表单上传 springMVC

1.页面

<form id="form1" method="post" enctype="multipart/form-data">

<input id="files" name="files" type="file" class="textfield" />

</form>

2.js

$.messager.progress();
 $('#form1').form('submit', {
     url:'uploadFile.do',
     onSubmit: function(){
   var isValid = $(this).form('validate');
   if (!isValid){
    $.messager.progress('close');
   }
   return isValid;
     },
     success:function(datas){
   $.messager.progress('close');
      var data = eval('(' + datas + ')');   
         if (data.success){
             alert(data.message)
         }
     }
 });

3.action

@RequestMapping("/uploadFile.do")
 public String uploadLicense(MultipartHttpServletRequest mRequest,HttpServletRequest request, HttpServletResponse response) throws Exception {
  try{
   Map<String, MultipartFile> fileMap = mRequest.getFileMap();
   MultipartFile mFile = fileMap.get("files");
   
   String fileName = mFile.getOriginalFilename();

}catch(Exception e){
   logger.error(e.getMessage(), e);
  }
  return null;
 }

相关推荐