日期:2014-05-19 浏览次数:20902 次
    response.setContentType("application/msword;charset=utf-8");
        try {
            response.setHeader("Content-Disposition",
                    "attachment;filename="+new String(wordName.getBytes("gbk"),"ISO8859_1"));
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream("文件地址"));
            bos = new BufferedOutputStream(response.getOutputStream());
            int n = 0;
            byte b[] = new byte[5 * 1024];
            while ((n = bis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bis.close();
                bos.close();
            } catch (Exception e) {
            }
        }
------解决方案--------------------
String fileName = "数据转换表信息导出.xls";
    if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {
        fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器
    } else if (request.getHeader("User-Agent").toUpperCase()
        .indexOf("MSIE") > 0) {
        fileName = URLEncoder.encode(fileName, "UTF-8"); // IE浏览器
    } else {
        fileName = Utils.toUtf8String(fileName);
    }
    response.setHeader("Content-Disposition", "attachment;filename="
        + fileName);