Filedownload.save 中文乱码 In ff3,but ok in ie6,ie7

asked 2009-04-24 08:02:59 +0000

jentrees gravatar image jentrees
51 1

updated 2013-04-04 07:07:16 +0000

sjoshi gravatar image sjoshi flag of India
3510 1 8
<window title="My First Window" border="normal" width="200px">

<button label="Download download.html">
    <attribute name="onClick">{
        java.io.InputStream is = desktop.getWebApp().getResourceAsStream("/test/download.html");
        if (is != null)
            Filedownload.save(is, "text/html", "中文.html");
            alert("/test/download.html not found");


The file name can't show Chinese in ff3,but show in ie6,ie7

delete flag offensive retag edit


You can post Bug to SF.net, ZK Team will handle it.

iantsai ( 2009-04-26 05:43:48 +0000 )edit

3 Answers

Sort by » oldest newest most voted

answered 2009-04-27 04:09:56 +0000

jumperchen gravatar image jumperchen
3869 2 8
http://jumperchen.blogspo... ZK Team

Due to the implementation of ZK file download, the Chinese encode of the file name seems not to be recognized by some browser, except IE.
Therefore, you may write a download page instead of ZK file download for Chinese file name.
You can also take a look at the "File download (Content-Disposition)" from the link


link publish delete flag offensive edit

answered 2013-03-22 16:34:02 +0000

honchy gravatar image honchy

我也遇到了同样的问题,现在使用的zk版本是 3.6.3 . 字符转码有问题.中文在IE FF Chrome上都是显示URLEncode的结果. 还没有好的处理方式

link publish delete flag offensive edit

answered 2013-12-12 05:44:26 +0000

benbai gravatar image benbai
2218 6


You can store your file name in session, use another fake name as a key then process it in a filter then do what you want to do as needed.

For example,


String FILE_DOWNLOAD_KEY = System.currentTimeMillis() + ".filedownload";
Sessions.getCurrent().setAttribute(FILE_DOWNLOAD_KEY, "透視表.xlsx");

Filedownload.save(out.toByteArray(), "application/vnd.ms-excel", FILE_DOWNLOAD_KEY); // file download

filter added to web.xml



package test;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestFilter implements Filter {

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        String uri = httpRequest.getRequestURI();

        if (uri.endsWith(".filedownload")) {
            // get key from request uri
            String key = uri.substring(uri.lastIndexOf("/")+1);
            // get original filename with key
            String fileName = (String)httpRequest.getSession().getAttribute(key);

            // get user agent
            String agent = httpRequest.getHeader("USER-AGENT");
            // preset disposition file name
            String dispositionFileName = fileName;
            // update disposition file name and uri with respect to browsers
            if (agent != null && agent.indexOf("MSIE") != -1) {
                dispositionFileName = URLEncoder.encode(fileName, "UTF8").replaceAll("%", "%25");
                uri = uri.replace(key, dispositionFileName).replace(httpRequest.getContextPath(), "");
            } else if ( agent != null && agent.indexOf("Mozilla") != -1) {
                byte[] fileNameBytes = fileName.getBytes("utf-8");
                dispositionFileName = "";
                for (byte b: fileNameBytes) {
                    dispositionFileName += (char)(b & 0xff);
                uri = uri.replace(key, dispositionFileName).replace(httpRequest.getContextPath(), "");

            // remove attribute to reduce memory consumption
            // forward to new uri to get correct file name
                .getRequestDispatcher(uri).forward(request, response);
        } else {
            // process next request in chain
            chain.doFilter(request, response);

     * Unused.
    public void init(FilterConfig config) throws ServletException {

     * Unused.
    public void destroy() {


actually neither of below fit my situation but it works after combine them



You can also refer to other thread discuss similar issue


link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2009-04-24 08:02:59 +0000

Seen: 1,017 times

Last updated: Dec 12 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More