关于form的enctype="multipart/form-data"的处理

 

DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(size);
try{
        items = upload.parseRequest(request);
        }catch(Exception _ex){
        error = "附件太大!";
            request.setAttribute("error", error);
                return mapping.findForward("failure");
        }
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
       if (item.isFormField()) {  //如果是普通表单
                 if(item.getFieldName().equals("board_id")) {
                 board_id = item.getString();
                  }else if(item.getFieldName().equals("TZNR")) {
                  article_content=item.getString();
                  }else if(item.getFieldName().equals("artice_title")) {
                  artice_title=item.getString();
                  }else if(item.getFieldName().equals("article_id")){
                  re_artice_id=item.getString();
                  //System.out.println("re_artice_id="+re_artice_id);
                  }
      } else {     //如果是文件域表单
                      is=item.getInputStream();//获得上传文件的输入流
  size=item.getSize();//文件大小
  filename=item.getName();
  if(!filename.equals("")){
filename=filename.substring(filename.lastIndexOf("\\")+1);
filename_exec = filename.substring(filename.lastIndexOf(".")+1);
  }
     }
  }
posted @ 2008-08-18 18:15  雨中漫步的太阳  阅读(879)  评论(0编辑  收藏  举报