posts - 325,  comments - 25,  trackbacks - 0

          1.download.jsp頁面

          <body>
           <s:url id="url" action="download"></s:url>
           <s:a href="%{url}">download file</s:a>
           </body>

          2.在webroot下創(chuàng)建一個文件,用于保存要下載的文件
            如image

          3.DownloadAction.java

          package com.test.action;

          import java.io.InputStream;

          import org.apache.struts2.ServletActionContext;

          import com.opensymphony.xwork2.ActionSupport;

          public class DownloadAction extends ActionSupport {
           
           private String inputpath;

           public void setInputpath(String inputpath) {
            this.inputpath = inputpath;
           }
           
           public InputStream getInputStream() throws Exception
           {
            return ServletActionContext.getServletContext().getResourceAsStream(inputpath);
           }
           public String execute() throws Exception {
                  return SUCCESS;
              }
          }



          4.struts.xml

          <package name="testdownload" extends="struts-default">
            <action name="download" class="com.test.action.DownloadAction">
             <param name="inputpath">/image/Mode.rar</param>
             <result name="success" type="stream">
              <param name="contentType">application/zip</param>
              <param name="inputName">inputStream</param>
               <param name="contentDisposition">filename="Mode.rar"</param>
                          <param name="bufferSize">4096</param>
             </result>
            </action>
           </package>
          posted on 2008-05-08 11:16 長春語林科技 閱讀(429) 評論(0)  編輯  收藏 所屬分類: struts2
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 个旧市| 广安市| 吉林市| 竹北市| 鄂尔多斯市| 汉中市| 夏河县| 桂平市| 河池市| 兴隆县| 云和县| 韶山市| 登封市| 乐昌市| 兴安县| 武鸣县| 郸城县| 台南市| 凭祥市| 伊金霍洛旗| 乌拉特前旗| 沅陵县| 二手房| 尼勒克县| 大竹县| 即墨市| 隆化县| 永泰县| 墨竹工卡县| 淮滨县| 汶上县| 株洲县| 叙永县| 徐水县| 安图县| 瓦房店市| 日照市| 偃师市| 诸城市| 沅陵县| 南丹县|