表单类型改成二进制之后   无法用request.getParameter方法获得   要用特殊手段以前在用commons-fileupload的时候,里面有判断是否是表单域,是的话遍历items,不过取出来需要自己去比对这个item对应表单的哪个input类型String name = xxxxxx,这样子得到的是一个参数名称  需要自己判断后取其值

解决方案 »

  1.   

    //系统临时文件夹构造文件项工厂对象
      DiskFileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
       int color_index = 0,size_index = 0 ;
      try {
    // 得到所有的表单域,它们目前都被当作FileItem
       List<FileItem> items = upload.parseRequest(request);
       Iterator itr = items.iterator();
       
       // 依次处理每个表单域
       while (itr.hasNext()) {
        FileItem item = (FileItem) itr.next();
        // 如果item是正常的表单域
        if (item.isFormField()) {
         String name = item.getFieldName();
                    String value = new String(item.getString().getBytes("iso-8859-1"),"UTF-8"); 
                   System.out.println("表单域名为:"+name+"表单域值为:"+value);
        }else { //不是正常的表单域就是上传文件的选择域
         if (item.getName() != null && !item.getName().equals("")) { //判断是否选取了文件
          String pictureName = item.getName();
          String fileName;
          if(item.getFieldName().equals("gd_Pictures")){
          fileName = "PictureofGood"+gd_Id+pictureName.substring(pictureName.indexOf("."));
          //给新商品的照片添加值
          newGoods.setGd_Pictures(MyUtil.coverTime(new Date())+"/"+fileName);
          }else{
          fileName = "ModelPictureofGood"+gd_Id+i+pictureName.substring(pictureName.indexOf("."));
          //给新商品的模特照片添加新值
          gd_MPictures[i]=MyUtil.coverTime(new Date())+"/"+fileName;
          //对数组添加一个值后即向后移一位
          i++;
          }
          File file = new File(getServletContext().getRealPath("/")+savePath+"/"+MyUtil.coverTime(new Date()));
           if(file.exists()){ //判断文件夹是否存在 ,如果存在则不需要建立
           
            }
            else {
            file.mkdirs(); //如果不存在,则建立文件夹
            }
          file = new File(getServletContext().getRealPath("/")+savePath+"/"+MyUtil.coverTime(new Date())+"/"+fileName);
          item.write(file);
          //System.out.println("成功!!");
         }else{ //未选择文件
        
         }
        }
       }
    你用Apache的fileupload试一试,在后台得到所有表单信息,在遍历判断该表单是正常表单域,还是文件域,
    这样就可以实现你要的效果了,
    这个代码是我很久以前写的    里面我删了一些  你可以参考一哈
      

  2.   

    ssh的话  你直接可以用structs处理
      

  3.   

    原来是少写了一个get方法,,,。谢谢各位大神了