ajaxfileupload.js实现上传文件功能

  @RequestMapping(value="/importPicFile.do" ,produces="text/html;charset=utf-8" )

  public @ResponseBody String importPicFile1(@RequestParam("picParams") String picParams,

  @RequestParam MultipartFile myfile,HttpServletRequest request){

  Map map= new HashMap();

  if(myfile.isEmpty()){

  map.put( "result", "error");

  map.put( "msg", "上传文件不能为空" );

  } else{

  String originalFilename=myfile.getOriginalFilename();

  String fileBaseName=FilenameUtils.getBaseName(originalFilename);

  String floderName=fileBaseName+"_" +DateUtil.getNowTimeData();

  try{

  String genePicPath=request.getSession().getServletContext().getRealPath("/upload/" +floderName);

  //把上传的图片放到服务器的文件夹下

  FileUtils. copyInputStreamToFile(myfile.getInputStream(), new File(genePicPath,originalFilename));

  //coding

  map.put( "result", "success");

  } catch (Exception e) {

  map.put( "result", "error");

  map.put( "msg",e.getMessage());

  }

  }

  String result=String. valueOf(JSONObject.fromObject (map));

  return result;

  }