webwork2 开发下载excel文件 解决扩展名乱码及在火狐下多出个逗号的处理

在webwork2 的action中处理:

 

 

 

public class TestDownLoadAction

{

        private String fileName ;

        //添加setter|getter方法

       public void downLoad()throws Exception

      {

              // 下载全部数据
                //pageIterator = stateBo.getStateList(storeId, null, null, "default",pageNo,pageSize);
                list = stateBo.getStateList(storeId, null, null, "default");

                String pathFile = new File(OpeExcel.class.getResource("/")
                        .toString()).getParent().toString();
                String pathFile_deal = pathFile.substring(6, pathFile.length());
                String filePath = new String((pathFile_deal + "\\download\\"
                        + storeId + ".xls").getBytes("ISO8859_1"), "utf-8");

                map.put("list1", list);
                OpeExcel.writeStatanaly(map, filePath);// 通过poi生成一个excel

                // 下载生成的excel文件
                try
                {
                    fileName = "统计分析";
                    //把文件名转码位"ISO8859-1"的格式,避免在弹出下载对话框时文件名是乱码
                    fileName = new String(fileName.getBytes("utf-8"),"ISO8859-1");
                    File input = new File(filePath);
                    excelStream = new FileInputStream(input);

                } catch (FileNotFoundException e)
                {
                    e.printStackTrace();
                }

      }

 

}

 

 

在xwork.xml里配置:

result name="download" type="stream">
                <param name="contentType">application/x-download;charset=UTF-8</param>
                 <param name="inputName">excelStream</param>
                 <param name="bufferSize">2048</param> 
                 <param name="contentDisposition">attachment;fileName="${fileName}.xls"</param>
 </result>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值