现然页面上有一个链接,是链接到了一个扩展名为kdh的文件,现在点击链接是将kdh文件直接在IE中以乱码形式打开了,怎么能才让点击是下载??是在tomcat中设置吗??

解决方案 »

  1.   


    response.setContentType( "Application;charset=UTF-8");
    File file = new File("../.....kdh");
    FileInputStream fis = new FileInputStream(file);
    byte[] result = new byte[fis.available()];
    fis.read(result);
    OutputStream of = response.getOutputStream();
    of.write(result);
    of.flush();不用设置tomcat
      

  2.   


    类似与TXT之类文件下载的,你得写下载类哈。要不直接肯定直接IE打开
      

  3.   

    下载方法 比如:
    /**
     * 下载文件
     */
    public void ExpZSSJ(){
    OutputStream os = null;
    String s = "application/octet-stream";
    try {
    os = getResponse().getOutputStream();
    getResponse().setContentType(s);
                    //设置默认下载文件名
    String fileName = URLEncoder.encode(*******.*", "UTF-8");
    // 设置文件下载头
    getResponse().addHeader("Content-Disposition", "attachment;filename="
    + fileName);
    drzssjservice.ExpZSData(os,getJhbm(),getJhdm());
    os.close();
    } catch (IOException e) {
    }
    }
    这个参数设置attachment就是默认不打开。另外如果不行就要看看你的ie的设置了。
      

  4.   

    这个中
    getResponse().addHeader("Content-Disposition", "attachment;filename="
                    + fileName);
    的这个,本意是想用红色提示你这个设置。但是颜色没有出来。不要受误导。
    [color=#FF0000]attachment
    ;
    正确的写法:
    getResponse().addHeader("Content-Disposition", "attachment;filename="
                    + fileName);
      

  5.   

    文件下载:
    首先要以 下载字节流的方式:
    application/octet-stream
    其次Content-Disposition属性设置
    ////attachment --- 作为附件下载
    ////inline --- 在线打开