-
FEATURED COMPONENTS
First time here? Check out the FAQ!
<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
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
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
Asked: 2009-04-24 08:02:59 +0800
Seen: 1,023 times
Last updated: Dec 12 '13
You can post Bug to SF.net, ZK Team will handle it.
iantsai ( 2009-04-26 05:43:48 +0800 )edit