六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 228|回复: 0

zk下载文件中文乱码解决方案

[复制链接]

升级  6.33%

63

主题

63

主题

63

主题

举人

Rank: 3Rank: 3

积分
219
 楼主| 发表于 2013-1-23 01:24:50 | 显示全部楼层 |阅读模式
 
本文来自http://sun4love.iteye.com/blog/1068254 转载请注明
 
IE,chrome,ff,opera测试通过
 
/** * User: sunflower * Date: 11-6-2 * Time: 上午10:45 */public class IndexController extends GenericForwardComposer {    public void onDownfile() {        try {            String charset = "UTF-8";            //服务器文件名            String fileName = "Sip坐席通讯协议.txt";            //编码后文件名            String encodedName = null;            encodedName = URLEncoder.encode(fileName,charset);            //将空格替换为+号            encodedName =encodedName.replace("%20","+");            HttpServletRequest httpRequest =(HttpServletRequest) Executions.getCurrent().getNativeRequest();            //解决ie6 bug 或者是火狐浏览器            if (encodedName.length() > 150                    ||Servlets.isGecko(httpRequest)                    ||Servlets.isGecko3(httpRequest)) {                encodedName = new String(fileName.getBytes(charset), "ISO8859-1");            }            Filedownload.save(new FileInputStream(ZkUtils.getRealPath("/" + fileName)),                    "application/octet-stream", encodedName);        } catch (Exception e) {        }    }}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表