关闭

extremecomponents extremetable的导出时中文文件名为乱码的问题解决

792人阅读 评论(0) 收藏 举报
 如果由于编码的设置问题引起extremetable在导出时中文文件名为乱码的问题,可以修改默认的ExportFilter加以解决(继承AbstractExportFilter)。

public class ExportFilter extends AbstractExportFilter {
private boolean responseHeadersSetBeforeDoFilter;

public void init(FilterConfig filterConfig) throws ServletException {
String responseHeadersSetBeforeDoFilter = filterConfig.getInitParameter("responseHeadersSetBeforeDoFilter");
if (StringUtils.isNotBlank(responseHeadersSetBeforeDoFilter)) {
this.responseHeadersSetBeforeDoFilter = new Boolean(responseHeadersSetBeforeDoFilter).booleanValue();
}
}

public void destroy() {}

protected void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain, String exportFileName) throws IOException, ServletException {

//导出时中文文件名为乱码的问题解决
String encoding=request.getCharacterEncoding();
if(encoding.equalsIgnoreCase("GBK")){
exportFileName =new String(exportFileName.getBytes("GBK"),"iso-8859-1");
}else if(encoding.equalsIgnoreCase("GB2312")){
exportFileName =new String(exportFileName.getBytes("GB2312"),"iso-8859-1");
}//如果是“utf-8”什么也不用干
if (responseHeadersSetBeforeDoFilter) {
setResponseHeaders((HttpServletResponse) response, exportFileName);
}
chain.doFilter(request, new ExportResponseWrapper((HttpServletResponse) response));
if (!responseHeadersSetBeforeDoFilter) {
setResponseHeaders((HttpServletResponse) response, exportFileName);
}

}
}

将web.xml中filter改为上面的即可

<filter>
<description>Extreme Table Export Filter</description>
<filter-name>eXtremeExport</filter-name>
<filter-class>上面的ExportFilter</filter-class>
<init-param>
<param-name>responseHeadersSetBeforeDoFilter</param-name>
<param-value>true</param-value>
</init-param>
</filter>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1985次
    • 积分:38
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档