日期:2014-05-18  浏览次数:20738 次

请教JSP文件上传
诸位高手,我是一JSP初学者,从网络中搜寻到了JSP中文件上传有关commons-fileupload-1.0.jar组件使用程序,文件上传倒是成功了,但是office(word、excel等)文档类文件上传以后打不开,提示:“文档的名称或路径无效。请试用如下建议:*检查文档或驱动器的文件权限;*使用‘文件’菜单中的‘打开’命令定位文档。(文档路径)”错误,吾辈不才,琢磨许日,不得其所,请教诸位大侠,事儿急,谢了!!!附程序片断:

<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   %>
<%@   page   import= "db.* "%>
<%@   page   import= "java.util.* "%>
<%@   page   import= "org.apache.commons.fileupload.* "%>
<%@   page   import= "java.io.* "   %>
<%@   include   file= "../common/checkUser.jsp "%>
<%


//String   logoName=null;
String   sumtheme=null;
String   year=null;
String   month=null;
String   day=null;
//String   datetime=null;
String   sumtext=null;


String   type=null;
//String   pathName=null;
String   msg   =   " ";
String   getMaxID   =   null;
String   name   =   null;
  String   thePath   =   null;        
    String   pathName   =   null;
DiskFileUpload   fu   =   new   DiskFileUpload();
//   设置允许用户上传文件大小,单位:字节
fu.setSizeMax(400000000);
//   设置最多只允许在内存中存储的数据,单位:字节
//fu.setSizeThreshold(4096);
//   设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
//fu.setRepositoryPath( "C:\\Temp ");
//开始读取上传信息
List   fileItems   =   fu.parseRequest(request);


//   依次处理每个上传的文件
Iterator   iter   =   fileItems.iterator();
while   (iter.hasNext())   {
    FileItem   item   =   (FileItem)   iter.next();
    if   (item.isFormField())   {
    String   fieldName   =   item.getFieldName();
//if   (fieldName.equals( "logoName "))   logoName=item.getString();
if   (fieldName.equals( "sumtheme "))   sumtheme=item.getString();

if   (fieldName.equals( "sumtext "))   sumtext=item.getString();
   
    }
    //忽略其他不是文件域的所有表单信息
    else   if   (!item.isFormField())   {
      name   =   item.getName();
      long   size   =   item.getSize();
      if((name==null||name.equals( " "))   &&   size==0)
      continue;


//保存上传的文件到指定的目录
      name   =   name.replace( ': ', '_ ');
      name   =   name.replace( '\\ ', '_ ');
     
      //获得文件名
     
      String   sql= "SELECT   max(ID)   FROM   psum_up ";
      getMaxID=DBAccess.selectUnique(sql);
      if   ( " ".equals(getMaxID)   ||   getMaxID==null)getMaxID= "0 ";
      name=name.substring(name.lastIndexOf( "_ ")+1,name.length());
        thePath= "d:/resin-3.0.8.1/webapps/custom/office/uploadfile/123/ ";
      File   file   = &nb