zk下载文件中文乱码解决方案
程序员文章站
2022-07-13 21:47:36
...
本文来自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) {
- }
- }
- }
你这也是一种方式,我也留下我的一种处理方式吧:
- Execution ex = Executions.getCurrent();
- HttpServletRequest request = (HttpServletRequest) ex.getNativeRequest();
- if (request.getHeader("User-Agent").indexOf("MSIE") != -1) {// ie
- docFilename = URLEncoder.encode(docFilename, "UTF-8");
- } else {// firefox
- docFilename = MimeUtility.encodeText(docFilename, "GBK", "B");
- }
上一篇: zk tooltiptext中换行
下一篇: matplotlib绘制正弦和余弦曲线
我用的是zk-5.0.5版本.