struts2 上传错误
struts2吧
全部回复
仅看楼主
level 1
catchfinally 楼主
struts2 文件上传时拦截器 只在控制台报错 也有国际化 也有<result name="input"> 但是没有返回到提交页面
2010年08月20日 03点08分 1
level 1
catchfinally 楼主
[一楼喂熊]顶
2010年08月20日 03点08分 2
level 1
catchfinally 楼主
什么破吧   [拍砖]
2010年08月23日 01点08分 3
level 1
JAVA实现文件上传的几个组件:
           1 SmartUpload 用的最多的一个组件,已经不再更新了,可以实现上传和下载     
           2 FileUpload Apache实现的文件上传组件,功能齐备     
           3 J2KUpload java2000实现的文件上传组件,全部使用内存,适合多个不超过10M的小文件
     下面具体说说FileUpload Apache实现的文件上传组件。
1、/** 按copy方式上传   */
Java代码  
public String uploadFile(){   
     /**保存的具体路径*/   
     String savepath = getSavePath();   
     /**根据保存的路径创建file对象*/   
     File file = new File(savepath);   
     if(!file.exists()){   
         /**创建此文件对象路径*/   
         file.mkdirs();   
     }   
     try {   
         /**使用的是:org.apache.commons.io.FileUtils FileUtils*/   
         FileUtils.copyFile(pic, new File(file,getPicFileName()));   
     } catch (IOException e) {   
         e.printStackTrace();   
     }   
     return SUCCESS;   
}   
public String uploadFile(){      /**保存的具体路径*/      String savepath = getSavePath();      /**根据保存的路径创建file对象*/      File file = new File(savepath);      if(!file.exists()){          /**创建此文件对象路径*/          file.mkdirs();      }      try {          /**使用的是:org.apache.commons.io.FileUtils FileUtils*/          FileUtils.copyFile(pic, new File(file,getPicFileName()));      } catch (IOException e) {          e.printStackTrace();      }      return SUCCESS; }
备注:
         1、getSavePath()方法中,ServletActionContext().getServletContext().getRealPath
(savePath+"\\"+getPicFileName());     ,这个主要是一个文件的实际路径

2011年05月14日 00点05分 4
level 1
      2、我个人认为这种方式是简单易用的。按copy方式上传使用的是Apache公司的
org.apache.commons.io.FileUtils包里的FileUtils.java。
2、/** 按字节方式上传   */
Java代码  
public String uploadFile(){        
     /** 文件的写操作 */    
     FileInputStream fis = null;    
     FileOutputStream fos = null;   
         /** 保存的路径 */   
     String savepath = getSavePath();   
     /** 根据保存的路径创建file对象 */   
     File file = new File(savepath);   
     /** file对象是否存在    */   
     if (!file.exists()) {   
         /** 创建此文件对象路径   */   
         file.mkdirs();   
     }   
     try {   
         /** 创建输入流 */   
         fis = new FileInputStream(pic);   
         /** 输出流 更据文件的路径+文件名称创建文件对象 */   
         fos = new FileOutputStream(file + "//" + getPicFileName());   
         /** 读取字节    */   
         byte b[] = new byte[1024];   
         int n = 0;   
         /** 读取操作    */   
         while ((n = fis.read(b)) != -1) {   
             /** 写操作    */   
             fos.write(b, 0, n);   
         }   
         /** 关闭操作   */   
         if (fis != null) {   
             fis.close();   
         }   
         if (fos != null) {   
             fos.close();   

2011年05月14日 00点05分 5
level 1
         }   
     } catch (Exception e) {   
         e.printStackTrace();   
     }   
     return SUCCESS;   
}   
public String uploadFile(){              /** 文件的写操作 */       FileInputStream fis = null;       FileOutputStream fos = null;          /** 保存的路径 */      String savepath = getSavePath();      /** 根据保存的路径创建file对象 */      File file = new File(savepath);      /** file对象是否存在    */      if (!file.exists()) {          /** 创建此文件对象路径   */          file.mkdirs();      }      try {          /** 创建输入流 */          fis = new FileInputStream(pic);          /** 输出流 更据文件的路径+文件名称创建文件对象 */          fos = new FileOutputStream(file + "//" + getPicFileName());          /** 读取字节    */          byte b[] = new byte[1024];          int n = 0;          /** 读取操作    */          while ((n = fis.read(b)) != -1) {              /** 写操作    */              fos.write(b, 0, n);          }          /** 关闭操作   */          if (fis != null) {              fis.close();          }          if (fos != null) {              fos.close();          }      } catch (Exception e) {          e.printStackTrace();      }      return SUCCESS; }
3、/** 按字符方式上传     即“三层管道”   */

2011年05月14日 00点05分 6
level 1

Java代码  
public String uploadFile(){   
     /** 文件的写操作 */   
     BufferedReader br =null;   
     BufferedWriter bw = null;      
     /** 保存的路径 */   
     String savepath = getSavePath();   
     /** 根据保存的路径创建file对象    */   
     File file = new File(savepath);   
     /** file对象是否存在   */   
     if (!file.exists()) {              
         /** 创建此文件对象路径   */   
         file.mkdirs();   
     }   
     try {   
         /**    创建一个BufferedReader   对象*/   
         br = new BufferedReader(new InputStreamReader(new FileInputStream   
   
(pic)));               
         bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream   
   
(file + "//" + getPicFileName())));   
               
         // 读取字节   
         char b[] = new char[1024];   
         int n = 0;   
         // 读取操作   
         while ((n = br.read(b)) != -1) {   
             // 写操作   
             bw.write(b, 0, n);   
         }   
         // 关闭操作   
         if (br != null) {   
             br.close();   
         }   
         if (bw != null) {   
             bw.close();   

2011年05月14日 00点05分 7
level 1
         }   
     } catch (Exception e) {   
         e.printStackTrace();   
     }   
     return SUCCESS;   
}   
public String uploadFile(){      /** 文件的写操作 */      BufferedReader br =null;      BufferedWriter bw = null;           /** 保存的路径 */      String savepath = getSavePath();      /** 根据保存的路径创建file对象    */      File file = new File(savepath);      /** file对象是否存在   */      if (!file.exists()) {                      /** 创建此文件对象路径   */          file.mkdirs();      }      try {          /**    创建一个BufferedReader   对象*/          br = new BufferedReader(new InputStreamReader(new FileInputStream   (pic)));                      bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream   (file + "//" + getPicFileName())));                       // 读取字节          char b[] = new char[1024];          int n = 0;          // 读取操作          while ((n = br.read(b)) != -1) {              // 写操作              bw.write(b, 0, n);          }          // 关闭操作          if (br != null) {              br.close();          }          if (bw != null) {              bw.close();          }      } catch (Exception e) {          e.printStackTrace();      }      return SUCCESS; }
    备注:
        第二种上传方式没有第三种上传方式效率高。
    建议:
           最好用第一种方式上传,次之使用第三种方式上传,最后再使用第二种方式上传。
struts2文件上传的采用的三种方式解析
http://www.chinamore.net/news/2011512/n594895.html

2011年05月14日 00点05分 8
1