struts2 文件下载

一、xml配置:

 

<!-- 下载注册程序 -->

<action name="downRegversKey" class="acAccounts" method="downloadFile">

     <!-- 下载现有文件 -->

     <param name="inputPath">/files_ocx</param>

     <!-- 初始文件名 -->

     <param name="fileName">${downFileName}</param>

     <!-- result的Type必须为stream -->

     <result name="success" type="stream">

          <!-- 下载文件类型 -->

          <param name="contentType">

               application/octet-stream;charset=ISO8859-1

          </param>

          <!-- 下载对话框所弹出的文件名 -->

          <param name="contentDisposition">

               fileName="zcglkey.exe"

          </param>

          <!-- 下载的InputStream流,Struts2自己动对应Action中的getDownloadFile方法,该方法必须返回InputStream类型 -->

          <param name="inputName">downloadFile</param>

     </result>

</action>

 

 

二、action 配置:
private String downFileName;
private InputStream downInputStream;
private String inputPath;

// 下载
public String downloadFile() {
     return SUCCESS;
}
public InputStream getDownloadFile() {
     try {
          return ServletActionContext.getServletContext()
                         .getResourceAsStream(this.inputPath + "/zcglkey.exe");
     } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
     }
     return null;
}

页面直接根据代理名访问。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值