response设置下载文件名无效。因为response 参数设置要在out对象加入数据之前

刚刚通过servlet 的 response  的 out对象回传文件时, 回传回去的文件一直都无法给他命名,显示的是我自己的类名。



因为我先out.write();再设置response参数  这样不行。


必须先设置response参数 如

                                response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=FillLocation.zip");


在写 out.write(相关byte数据);

原文地址:https://www.cnblogs.com/fangyuandoit/p/13713880.html