sun4love 发表于 2013-1-23 01:24:50

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

 
本文来自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) {      }    }}
页: [1]
查看完整版本: zk下载文件中文乱码解决方案