0

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

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

jentrees gravatar image jentrees
51 1

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

sjoshi gravatar image sjoshi flag of India
3464 8
http://zkframeworkhint.bl...
<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");
        else
            alert("/test/download.html not found");
    }
    </attribute>
</button>

</window>

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

delete flag offensive retag edit

Comments

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

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

3 Answers

Sort by » oldest newest most voted
0

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

jumperchen gravatar image jumperchen
3829 1 8
http://jumperchen.blogspo... ZK Team

Hi,
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

/Jumper

link publish delete flag offensive edit
0

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

honchy gravatar image honchy
0

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

link publish delete flag offensive edit
0

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

benbai gravatar image benbai
2198 6
http://www.zkoss.org

Hi,

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,

filedownload-fragment:

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

<filter>
    <filter-name>testFilter</filter-name>
    <filter-class>test.TestFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>testFilter</filter-name>
    <url-pattern>*</url-pattern>
</filter-mapping>

TestFilter.java

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
            httpRequest.getSession().removeAttribute(key);
            // forward to new uri to get correct file name
            httpRequest.getSession().getServletContext()
                .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() {
    }
}

References:

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

http://stackoverflow.com/questions/10702683/is-there-a-common-way-to-download-all-types-of-files-in-jsp

http://stackoverflow.com/questions/5325322/java-servlet-download-filename-special-characters

You can also refer to other thread discuss similar issue

http://marsvaadin.iteye.com/blog/1405098

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

Follow

RSS

Stats

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

Seen: 1,011 times

Last updated: Dec 12 '13

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