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

急加班中,大侠帮看下文件下载的后缀名为什么是.zip?该怎么处理

2012-06-07 
急,加班中,大侠帮看下文件下载的后缀名为什么是.zip?Java codepublic ActionForward outputBlob(ActionMap

急,加班中,大侠帮看下文件下载的后缀名为什么是.zip?

Java code
public ActionForward outputBlob(ActionMapping mapping, ActionForm form, HttpServletRequest request,            HttpServletResponse response) {        DynaBean dynaform = (DynaBean) form;        Long attid = Long.valueOf((String) dynaform.get("attid"));        DcProjectatt dcProjectatt = dcProjectattMag.getObjectById(attid);        String attcontent = dcProjectatt.getAttpath();        try {            File file = new File(attcontent);            InputStream is = new FileInputStream("D:\\tomcat\\webapps\\ccms\\u\\cms\\www\\201206\\041559429329.xlsx");            @SuppressWarnings("unused")            int length = 0;            byte[] buf = new byte[1024];            while ((length = is.read(buf)) != -1) {                response.getOutputStream().write(buf);            }            is.close();        } catch (Exception e) {            e.printStackTrace();        }        return null;    }

HTML code
<td align="left">                    <a href="${ctx}/zxsb/dcProjectatt.do?method=outputBlob&attid=${dcProjectatt.attid}" target="_blank"><c:out                            value="${dcProjectatt.attname}" />                    </a>                </td>

页面点击下载的时候为什么默认文件的后缀名是.zip 压缩的形式啊?

[解决办法]
设置一下HTTP头信息
Java code
// 设置response的Headerresponse.addHeader("Content-Disposition", "attachment;filename=" + "041559429329.xlsx");response.addHeader("Content-Length", "" + file.length());response.setContentType("application/octet-stream");
[解决办法]
探讨
引用:
设置一下HTTP头信息

Java code


// 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + "041559429329.xlsx");
response.addHeader("Content-Length", "" + fil……

热点排行