首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

commons-uploadfile上传文件时无法得到返回的异常信息

2014-01-26 
commons-uploadfile上传文件时无法得到返回的异常信息:代码如下:public void doPost(HttpServletRequest re

commons-uploadfile上传文件时无法得到返回的异常信息:

代码如下:

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 
  String saveDirectory = gbs.getBasicSetting("UploadFile.saveDirectory");
  String tmpDirectory = gbs.getBasicSetting("UploadFile.tmpDirectory");
  int maxPostSize = 1024 * 1024;
  String FileName = null;
  long FileSize = 0;
  String strErr = null;
 
  try {
  response.setContentType(CONTENT_TYPE);
  PrintWriter out = response.getWriter();
 
  DiskFileUpload upload = new DiskFileUpload();
  upload.setSizeThreshold(Integer.parseInt(gbs.getBasicSetting("UploadFile.sizeThreshold")));
  upload.setSizeMax(maxPostSize);
  upload.setRepositoryPath(tmpDirectory);
 
  List items = null;
  items = upload.parseRequest(request);
  Iterator iter = items.iterator();
  FileItem item = (FileItem) iter.next();
 
  FileName = item.getName();
  FileName = FileName.substring(FileName.lastIndexOf("\\") + 1);
  FileName = FileName.substring(FileName.lastIndexOf("/") + 1);
 
  FileSize = item.getSize();
  if (FileSize == 0) {
  strErr = "请选择上传文件!";
  }
  if (strErr != null) {
  out.println("<script language=\"javascript\">alert('" + strErr + "');history.go(-1);</script>");
  }
  else {
  out.println(FileSize);
  File uploadedFile = new File(saveDirectory + FileName);
  item.write(uploadedFile);
  }
 
  }
  catch (Exception ex) {
  System.out.println("错误");
  }
  }
 
  限制上传文件大小后 上传超过小文件通过 但上传大文件 显示内容为空 如何才能捕捉到返回的异常?

------解决方法--------------------------------------------------------
我也加了上传的包,怎么找不到DiskFileUpload这个类呢
------解决方法--------------------------------------------------------
你上网查一下资料!应该是缺一个jar,是环境不对!在tomcat网站上有!我前天下了一个,配置上就好了!

        

热点排行