“内容处置”不起作用

时间:2018-07-18 04:40:04

标签: java

我不擅长下载。 但是,没有出现下载屏幕。 源未发生错误。

为什么不起作用?

谢谢。

代码:

        String destFileName = "TEST.xls";

        StringBuffer contentDisposition = new StringBuffer();
        contentDisposition.append("attachment;fileName=\"");
        contentDisposition.append(new String(destFileName.getBytes(), "ISO-8859-1"));
        contentDisposition.append("\"");


        response.setHeader("Content-Disposition", contentDisposition.toString());
        //response.addHeader("Content-Disposition", contentDisposition.toString());
        //response.setContentType("application/x-msexcel");
        response.setContentType("application/vnd.ms-excel");

1 个答案:

答案 0 :(得分:1)

文件名令牌应使用RFC中指定的小写字母:

19.5.1 Content-Disposition

        content-disposition = "Content-Disposition" ":"
                              disposition-type *( ";" disposition-parm )
        disposition-type = "attachment" | disp-extension-token
        disposition-parm = filename-parm | disp-extension-parm
        filename-parm = "filename" "=" quoted-string
        disp-extension-token = token
        disp-extension-parm = token "=" ( token | quoted-string )

=> contentDisposition.append(“ attachment; 文件名 = ...”);