Struts2 下载文件文名名中文问题
作者:liuqing
strut.xml 文件配置
?
这是配置下载文件格式 类型
?
<package name="jkjy_1" namespace="/jkjy" extends="phs-default"> <action name="jkjyhd_fbAction_*" method="{1}"> <result name="success">/jkjy/uploadFile/uploadFile_add.jsp</result> <result name="list">/jkjy/uploadFile/uploadFile_list.jsp</result> <result name="delete" type="redirectAction">jkjy/jkjyhd_fbAction_list</result> <result name="download" type="stream"> <param name="contentType">application/octet-stream;charset=ISO8859-1</param> <param name="inputName">downloadInputStream</param> <param name="contentDisposition">attachment;filename="${downloadFilename}"</param> <param name="bufferSize">4096</param> </result> </action>?
下载文件名乱码关键
?
/** * 下载文件 * @return String */public String download() {this.jkjyhd_fb = this.jkjyhd_fbService.get(this.jkjyhd_fb.getId());try {this.downloadInputStream = this.jkjyhd_fbService.downloadFile(this.jkjyhd_fb.getType(), this.jkjyhd_fb.getId());this.downloadFilename = new String(this.jkjyhd_fb.getFilename().getBytes(),"iso-8859-1");}catch (Exception e) {e.printStackTrace();this.error("文件已经被册除!");}return "download";}?
导出Excel 问题
?
<action name="jhsy_hjcxAction_*" type="stream"> <param name="contentType"> application/vnd.ms-excel </param> <param name="inputName">inputStream</param> <param name="contentDisposition"> filename="Report_jhsy_hjcx.xls" </param> <param name="bufferSize">1024</param> </result> </action>
?
?
/** * 导出Excel 文件 * @return String * @throws Exception */public String exportExcel() throws Exception{//日期格式转换this.pageInfo.setPageSize(20000);Date start_date = TypeConvert.strToDate(this.start_time);Date end_date = TypeConvert.strToDate(this.end_time);//中文乱码问题解方法person.setName(TypeConvert.iso_To_Utf_8(person.getName()));//导出if("0".equals(v_lx)){ this.inputStream = this.jhsy_hqjcService.exportExcel(pageInfo, person, this.initHospital, start_date, end_date);}else if("1".equals(v_lx)){this.inputStream = this.jhsy_sxzzSzService.exportExcel(pageInfo, person, this.initHospital, start_date, end_date);}else if("2".equals(v_lx)){this.inputStream = this.jhsy_sxzzXzService.exportExcel(pageInfo, person, this.initHospital, start_date, end_date);}else if("3".equals(v_lx)){this.inputStream = this.jhsy_yyService.exportExcel(pageInfo, person, this.initHospital, start_date, end_date);}return EXPORT_EXCEL;}?
?
?
?