现在我采用上传如下<input type="file" ...在弹出的窗口中,有个文件类型,我想限制这个文件类型,比如只能上传zip包,那就在弹出的窗口中,只显示后缀名为zip的文件,其他的文件都过滤掉
这个应该比较难吧,不需要在点击upload的时候,再用js去判断,这样效果不是很好
或者用别的形式,如flash的形式,都可以,谢谢大家咯

解决方案 »

  1.   

    在FLASH中我们可以这样限制在浏览文件时就只显示需要的文件类型MP3。
    import flash.net.FileReferenceList;
    var fileRef:FileReferenceList = new FileReferenceList();
    var allTypes:Array = [];
    var 浏览类型:Object = new Object();
    浏览类型.description = "浏览类型(*.mp3)";
    浏览类型.extension = "*.mp3";
    allTypes.push(浏览类型);
    fileRef.browse(allTypes);
      

  2.   

    Flash 获取不到完整文件路径吧。。
      
      

  3.   

    用Struts2可以实现,  写个文件上传的过滤器,再上传的时候就可以先对上传文件进行判断,之后再提交给Action执行上传功能,使用的组件是 apache的commons-fileupload组件。
      

  4.   


    java多文件上传(通过commos包中的DiskFileUpload的类来重新封装请求) public ActionForward execute(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response) {
      // TODO Auto-generated method stub
      /*
       * PicForm pForm=(PicForm)form; FormFile file=pForm.getFile();
       * //获取上传的绝对路径 String
       * path=this.getServlet().getServletContext().getRealPath("/upload");
       * //获取文件名 String
       * filename=System.currentTimeMillis()+file.getFileName(); //上传的绝对路径
       * String filepath=path+"/"+filename; try { FileOutputStream fos=new
       * FileOutputStream(filepath); fos.write(file.getFileData());
       * fos.flush(); fos.close(); System.out.println("上传成功"); } catch
       * (Exception e) { // TODO: handle exception }
       */
      try {
       String dir = servlet.getServletContext().getRealPath("/upload");
    //   String path = this.getServlet().getServletContext().getRealPath(
    //   "/img");
       DiskFileUpload dfu = new DiskFileUpload();
       // 设置上传数据的最大大小为10M。
       dfu.setSizeMax(0xA00000);   // 设置内存缓冲区的阀值为512K。
       dfu.setSizeThreshold(0x80000);   // 设置临时存储文件的目录为E:\fileupload。
       dfu.setRepositoryPath("E:\\fileupload");   // 得到FileItem对象的列表。
       List fileItems = null;   fileItems = dfu.parseRequest(request);
       Iterator it = fileItems.iterator();
       while (it.hasNext()) {
        FileItem item = (FileItem) it.next();
        String filename = new String(item.getName().getBytes(
          "ISO8859-1"), "utf-8");
    //    System.out.println(item.getName() + item.getContentType()
    //      + item.getFieldName());
        
        System.out.println(item.getContentType());
        System.out.println(filename.substring(filename.lastIndexOf(".")));
        String filepath = dir + "/" + filename.substring(filename.lastIndexOf("\\"));
        item.write(new File(filepath));
        System.out.println("success");
       }
      } catch (Exception e) {
       e.printStackTrace();
      }  return null;
     }
    楼主参考一下,希望对你有用
      

  5.   

    LZ用SwfUPload控件 自己骨骼一下 能满足LZ要求
      

  6.   


    flash是可以过滤后缀名的,但是我不太清楚怎么去结合还得麻烦再讲明白些