zoukankan      html  css  js  c++  java
  • layui upload上传文件动态传参,后台获取不到值

    废话不多说,直接上代码

    js:

    layui.use('upload', function(){
            var $ = layui.jquery,upload = layui.upload;
            //绑定原始文件域
            upload.render({
                elem: '#test20'
                ,url: "<c:url value='/order/imgUpload.do?proVal=IMG_PATH'/>" 
                ,auto: true
                ,accept: 'file'
                ,exts:"jpg|png|gif|jpeg|bmp"
                ,size:1024
                ,before: function(obj){
                    var orderID = $("#orderID").val();
                    this.data={"orderID":orderID}//携带动态参数
                }
                ,done: function(res){
                    if(res.msg=='ok'){
                        alert('上传成功');
                    }else{
                        alert(res.msg);
                    }
                }
            });
       });

    java:

    上传文件的代码我没写,主要写了怎么取这个动态参数的值

    @ResponseBody
    @RequestMapping(
    "/imgUpload") public JsonResult imgUpload( HttpServletRequest request,HttpServletResponse response,ModelMap map ){ JsonResult json = new JsonResult(); Integer orderID = null;//订单ID DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(10240000); try { ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("utf-8"); @SuppressWarnings("rawtypes") List fileList = null; try { fileList = upload.parseRequest(request); } catch (FileUploadException ex) { return null; } @SuppressWarnings("unchecked") Iterator<FileItem> it = fileList.iterator(); //取参数 while (it.hasNext()) { FileItem item = it.next(); if(item.isFormField()&&"orderID".equals(item.getFieldName())){ orderID = Integer.valueOf(item.getString()); } }

    if(orderID==null){ json.setMsg("参数有误,请刷新重试!"); return json; } } catch (Exception e) { e.printStackTrace(); json.setMsg("上传失败"); }finally{ factory = null; } return json; }
  • 相关阅读:
    failonerror on MSBuild
    近期Windows Mobile问题汇总
    android的文件操作 sdcard和rom
    用实际库存数调整批次保留最新的批次
    各种布局layout
    javascript让ui线程让出时间片的模型
    android ListView控件操作绑定数据、单击事件
    Pocket PC 模拟器上网设置
    android单元测试
    打电话发短信
  • 原文地址:https://www.cnblogs.com/guaiguaipaizz/p/14334707.html
Copyright © 2011-2022 走看看