首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

上载及中文乱码

2012-08-29 
下载及中文乱码@Action(export)public void exportWord(){plan service.showInfo(plan)File file n

下载及中文乱码
@Action("export")
public void exportWord(){
        plan = service.showInfo(plan);
        File file = null;
file = service.createWord(plan,imgBase64);[color=orange]
SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd");
String a5 = format2.format(new Date());
fileName = plan.getRp_name() + a5 +".doc";
String agent = request.getHeader("USER-AGENT");
if(null != agent && -1 != agent.indexOf("MSIE")){
fileName = URLEncoder.encode(fileName,"UTF-8");
}else if(null != agent && -1 != agent.indexOf("Mozilla")){
        fileName = new String(fileName.getBytes("UTF-8"),"iso-8859-1");
}

if (file.exists()) {
this.inputStream = new FileInputStream(file);
} else {
m_StringResult = "导出失败";
return;
}
response.reset();
response.setContentType("application/x-msdownload");
        response.addHeader("Content-Disposition", "attachment; filename="" + fileName + """);
        int fileLength = (int) file.length();
        response.setContentLength(fileLength);
        /*如果文件长度大于0*/
        if (fileLength != 0) {
                /*创建输入流*/
                byte[] buf = new byte[4096];
                /*创建输出流*/
                ServletOutputStream servletOS = response.getOutputStream();
                int readLength;
                while (((readLength = this.inputStream.read(buf)) != -1)) {
                    servletOS.write(buf, 0, readLength);
                }
                this.inputStream.close();
                servletOS.flush();
                servletOS.close();
            }
}catch(Exception e){
        e.printStackTrace();
}
}

热点排行