永发信息网

Spring mvc框架 MutipartFile+flex上传文件,后得怎么得不到文件信息

答案:1  悬赏:60  手机版
解决时间 2021-08-22 15:32
  • 提问者网友:精神病院里
  • 2021-08-22 05:37

Flex代码
//导入
              private var selectFile:FileReference = new FileReference();;
             private var request:URLRequest;
             public function _import():void{
             Security.allowDomain("*");
              var textFile:FileFilter = new FileFilter("Files (*.xls)","*.xls");
              selectFile.browse(new Array(textFile));
             selectFile.addEventListener(Event.SELECT,selectHandler);  
            }

            private function selectHandler(event:Event):void{
             var upLoadFiles:FileReference = FileReference(event.target);
              request = new URLRequest("http://localhost:8080/webgis/common/import.do");
              request.method = "post";
             request.data = "files="+upLoadFiles.name;
             selectFile.upload(request);
            }

            <mx:Button label="导 入" click="_import()" width="60" height="20"/>

 

JAVA后台
           @Controller(".do")
         public class ImportAction {
 @RequestMapping
 public void execute(HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  System.out.println("run in import");
  
  // 创建一个通用的多部分解析器.
  CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
    request.getSession().getServletContext());
  // 设置编码
  commonsMultipartResolver.setDefaultEncoding("utf-8");
  // 判断是否有文件上传
  if (commonsMultipartResolver.isMultipart(request)) {
   MultipartHttpServletRequest multipartRequest = commonsMultipartResolver
     .resolveMultipart(request);
   Iterator iter = multipartRequest.getFileNames();
//iter里面没有值
   while (iter.hasNext()) {
    MultipartFile file = multipartRequest.getFile((String) iter
      .next());
    if (file != null) {
     File localFile = new File(file.getOriginalFilename());
     file.transferTo(localFile);
    }
   }
  }
          }

最佳答案
  • 五星知识达人网友:往事埋风中
  • 2021-08-22 06:28
jsp方向嘛,你就应该 学习一下 spring hibernate struts(SSH)单独的Spring呢,主要学习一下Spring 的MVC.学习一下jsp servlet。还有权限认证 acgi 等。其他的还要学习和熟悉 html语法 JavaScript,XML。各种数据库
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯