xiaochao

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            1 隨筆 :: 6 文章 :: 48 評(píng)論 :: 0 Trackbacks

          struts2 文件下載類是很簡(jiǎn)單的,代碼:

           1 package test.filedown
           2 
           3 import java.io.InputStream;
           4 import com.forlink.wps.template.dao.TemplateJackrabbitDao;
           5 import com.forlink.wps.template.dao.impl.TemplateJackrabbitDaoImpl;
           6 import com.forlink.wps.template.dto.TemplateDTO;
           7 import com.opensymphony.xwork2.ActionSupport;
           8 
           9 public class FileDownloadAction extends ActionSupport
          10 {
          11 
          12     private String    inputPath;
          13 
          14     private String    contentType;
          15     
          16     private String filename;
          17     
          18 
          19     public InputStream getInputStream() throws Exception
          20     {
          21         return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
          22 
          23     }
          24 
          25     public String execute() throws Exception
          26     {
          27         inputPath="/image/close_w.gif";//要下載的文件名稱
          28         filename="test.gif"//保存文件時(shí)的名稱
          29         contentType="image/gif";//保存文件的
          30             return SUCCESS;
          31     }
          32 
          33 
          34     public String getContentType()
          35     {
          36         return contentType;
          37     }
          38 
          39     public void setContentType(String contentType)
          40     {
          41         this.contentType = contentType;
          42     }
          43 
          44     public String getFilename()
          45     {
          46         return filename;
          47     }
          48 
          49     public void setFilename(String filename)
          50     {
          51         this.filename = filename;
          52     }
          53 }
          54 
          主要是在Action的配置上,配置文件如下:
          <action name="filedownload"
                      class
          ="test.filedown.FileDownloadAction">
                      
          <result name="success" type="stream">
                          
          <param name="contentType">${contentType}</param>
                          
          <param name="inputName">inputStream</param>                
                          
          <param name="bufferSize">4096</param>
                          
          <param name="contentDisposition">filename="${filename}"</param>
                          
          <param name=""></param>
                      
          </result>
          </action>
          posted on 2007-09-21 09:32 小超 閱讀(4011) 評(píng)論(5)  編輯  收藏 所屬分類: struts2

          評(píng)論

          # re: struts2文件下載 2008-09-16 11:15 小數(shù)
          嚴(yán)重: Servlet.service() for servlet default threw exception
          java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
          at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:189)
          老提示這個(gè)錯(cuò)什么意思
          action里有哪個(gè)方法啊  回復(fù)  更多評(píng)論
            

          # re: struts2文件下載 2008-12-15 20:32 群哥
          <param name="inputName">inputStream</param> 這一行寫錯(cuò)了inputStream  回復(fù)  更多評(píng)論
            

          # re: struts2文件下載 2009-02-23 16:18 sfdsf
          @小數(shù)
            回復(fù)  更多評(píng)論
            

          # re: struts2文件下載 2009-05-05 10:49 zhenglsuhagn
          @sfdsf
          很可能的原因是在寫的文件路徑中,沒(méi)有找到對(duì)應(yīng)的文件  回復(fù)  更多評(píng)論
            

          # re: struts2文件下載 2010-05-08 10:34 zjlg
          @zhenglsuhagn
          是這個(gè)原因,inputname這個(gè)取不到值  回復(fù)  更多評(píng)論
            


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 南丹县| 广灵县| 郑州市| 新巴尔虎右旗| 瑞丽市| 资溪县| 大石桥市| 凌云县| 柯坪县| 彰化县| 东山县| 肥西县| 德州市| 乌什县| 云龙县| 邻水| 平江县| 许昌市| 临清市| 安丘市| 南皮县| 定兴县| 长武县| 沈丘县| 崇礼县| 武定县| 徐汇区| 望谟县| 宁武县| 禹州市| 麦盖提县| 喀什市| 抚松县| 诸城市| 靖西县| 马边| 海淀区| 普陀区| 江西省| 建瓯市| 邹平县|