文件下载,环境移到linux乱码问题
客户端
function downLoad(tdFileId){var paySaveFileName = document.getElementById(tdFileId).paySaveFileName;var payUploadFileName = document.getElementById(tdFileId).payUploadFileName;payUploadFileName = escape(encodeURIComponent(payUploadFileName));if(paySaveFileName!=''&&isExist(paySaveFileName)){window.location.href="<%=URL%>orderInfo/orderDownLoad.action?downFileName="+payUploadFileName+"&ext2="+paySaveFileName;}else{ alert("付款凭证不存在,请重新上传!");}}
<!-- 下载报告的Action定义 --><action name="orderDownLoad" type="streamx"> <param name="contentType">text/plain</param><param name="inputName">inputStream</param> <!-- 使用经过转码的文件名作为下载文件名,downloadFileName属性 对应action类中的方法 getDownloadFileName() --> <param name="contentDisposition">attachment;filename="${downloadFileName}"</param> <param name="bufferSize">5242880</param> </result> </action>
public String getDownloadFileName() throws Exception {String downFileName =request.getParameter("downFileName");downFileName = URLDecoder.decode(downFileName, "UTF-8");response.setHeader("Content-Disposition", "attachment; filename="+new String(downFileName.getBytes("gb2312"),"iso-8859-1")); try {// 一定要这样处理下,转换成ISO8859方式的西欧字符集。downFileName = new String(downFileName.getBytes(), "ISO8859-1");} catch (UnsupportedEncodingException e) {e.printStackTrace();}return downFileName;}