使用uploadify3.2.1 formData传递其他参数到后台,JAVA后台获取参数方法

后台服务端代码如下:
“`public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

    //设置接收的编码格式
    request.setCharacterEncoding("UTF-8");
    Date date = new Date();//获取当前时间
    SimpleDateFormat sdfFileName = new SimpleDateFormat("yyyyMMddHHmmss");
    SimpleDateFormat sdfFolder = new SimpleDateFormat("yyMM");
    String newfileName = sdfFileName.format(date);//文件名称
    String fileRealPath = "";//文件存放真实地址
    String fileRealResistPath = "";//文件存放真实相对路径
    //名称  界面编码 必须 和request 保存一致..否则乱码
    String name = request.getParameter("name");


   String arg="";



    String sql="";
    String filePath="";
    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String uploadTime=format.format(date);
    String firstFileName="";
    // 获得容器中上传文件夹所在的物理路径
    String savePath = this.getServletConfig().getServletContext().getRealPath("/") + "uploads//" + newfileName +"//";
    System.out.println("路径" + savePath +name);
    File file = new File(savePath);
    if (!file.isDirectory()) {
        file.mkdir();
    }
    try {
        DiskFileItemFactory fac = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(fac);
        upload.setHeaderEncoding("UTF-8");
        // 获取多个上传文件
        List fileList = fileList = upload.parseRequest(request);
        // 遍历上传文件写入磁盘
        Iterator it = fileList.iterator();
        while (it.hasNext()) {



            FileItem item = (FileItem) it.next();
                **if(item.getFieldName().equals("arg")){//前台的参数传递的名字,
                arg=item.getString(); //获得表单参数!!!!!
                }**
            // 如果item是文件上传表单域
            // 获得文件名及路径
            String fileName = item.getName();
            System.out.println("文件名:"+fileName);





                    }catch( Exception e) {
                        e.printStackTrace();
                    }*/
                    System.out.println("保存到数据库:");
                    System.out.println("name:"+name);
                    System.out.println("虚拟路径:"+fileRealResistPath);
                }

            }
        }
    } catch (FileUploadException ex) {
        ex.printStackTrace();
        System.out.println("没有上传文件");
        return;
    }
    response.getWriter().write("1");

}```
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页