前段时间应用jxls做了excel导出功能,文件名自命为英文名,后来需求人中要求改为中文,这件事苦恼了我数天,在网上搜也没有找到太好的解决办法,今天终于找到了最简单有效的办法。代码如下:
<%@ page contentType="text/html; charset=GBK" %>
<%@ include file="/common/jsp/include.jsp"%>
<%@ include file="/common/js/utility/String.js"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%
String attempStr = (String)com.boco.webmaster.startup.WMClientCfg.getInstance().getSubSystemUrl().get("webattempSysStartUri"); //attempStr是服务地址,如http://10.0.7.111:9900/webmaster
String contextPath = attempStr+"//exportFile";
String fileName = request.getParameter("filename");
String filepath = contextPath+"//"+URLDecoder.decode(fileName,"UTF-8");
%>
<script type="">
window.location.href='<%=filepath%>';
</script>
本文介绍了如何在jsp中解决中文文件名下载的问题。通过设置contentType为GBK,结合URLDecoder进行解码,实现了从指定服务器地址下载带有中文名称的Excel文件。
1215

被折叠的 条评论
为什么被折叠?



