使用struts2导出excel,
struts.xml文件中这样配置的文件名:<action name="exportexcel" class="BeenChina.PM.Action.CaseNumberEfficiencyQuery">
<result name="success" type="stream">
...
<param name="contentDisposition">attachment;filename="${fileName}.xls"</param>
...
</result>
</action>
Action的fileName属性的get方法:public String getFileName() throws UnsupportedEncodingException {
fileName=new String(fileName.getBytes(),"ISO8859-1");
return fileName;
}public void setFileName(String fileName) throws UnsupportedEncodingException {
this.fileName=fileName;
}
现在的问题是:为什么要用ISO8859-1才可以使下载文件名不是乱码,而UTF-8却不行?
struts.xml文件中这样配置的文件名:<action name="exportexcel" class="BeenChina.PM.Action.CaseNumberEfficiencyQuery">
<result name="success" type="stream">
...
<param name="contentDisposition">attachment;filename="${fileName}.xls"</param>
...
</result>
</action>
Action的fileName属性的get方法:public String getFileName() throws UnsupportedEncodingException {
fileName=new String(fileName.getBytes(),"ISO8859-1");
return fileName;
}public void setFileName(String fileName) throws UnsupportedEncodingException {
this.fileName=fileName;
}
现在的问题是:为什么要用ISO8859-1才可以使下载文件名不是乱码,而UTF-8却不行?
解决方案 »
- 我想实现通过点击,然后执行函数,但是下面的代码实现不了
- 请教一个spring数据源的问题
- ckeditor在jsp中的应用,一定要来人啊。
- 怎样实现将GB2312编码的字符串转换为ISO-8859-1编码的字符串
- java 表单提交乱码问题
- Java高手请进动态页面问题
- hashset最多容纳多少个元素
- 用集合映射的hibersnate的*.hbm.xml配置文件必须要手写吗?
- 请问大家java的窗体尺寸改变以及最大化是触发哪个事件啊?
- 关于jbuilder7中建立实体ejb无法加载驱动的怪问题!请大虾近来看一下!如解决,分全送!·
- hibernate json 多对一 如何在取出多的时候关联取出一的数据
- 网页版图书管理系统遇到的问题
在tomcat的安装目录下找到
server.xml。
找到下面这段:看看你那里面设置的是什么。
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
我的默认配置是这样的:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
我的默认配置是这样的:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
没加的话默认就是ISO,你加上的话就等于修改了默认编码格式。比如加上UTF-8后那么就是UTF-8传输了。
我的默认配置是这样的:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
没加的话默认就是ISO,你加上的话就等于修改了默认编码格式。比如加上UTF-8后那么就是UTF-8传输了。我发现用ISO8859-1,firfox和Chrome好用,IE却找不到文件了。
String agent = request.getHeader("USER-AGENT" );
if( null != agent && - 1 != agent.indexOf( "MSIE" )) {
return URLEncoder.encode(fileName, "UTF8" );
}
else if ( null != agent && - 1 != agent.indexOf( "Firefox" )) {
return "=?UTF-8?B?" +( new String(Base64.encodeBase64(fileName.getBytes( "UTF-8" ))))+ "?=" ;
}
else if ( null != agent && - 1 != agent.indexOf( "Chrome" )) {
return new String(fileName.getBytes(), "ISO8859-1");
}
else{
return fileName;
}
}
好用是好用了,不知道这样做合适不?