注册 登录
编程论坛 J2EE论坛

关于下载页面的制作

macrossyun 发布于 2008-07-05 13:34, 1354 次点击
我做了个下载的界面,可是在JSP下无法显示,总是报网页无法显示,可是用servlet写了同样的代码就能通过了。不知道为什么。谁能解释下。关键部分代码如下:

             response.setContentType("application/x-zip-compressed");
        ServletOutputStream out=response.getOutputStream();
        File f=null;
        BufferedInputStream buf=null;
        try{
        f=new File("C:\\xx.zip");
        response.setContentLength((int)f.length());
        FileInputStream input=new FileInputStream(f);
        buf=new BufferedInputStream(input);
        int readBytes=0;
        while((readBytes=buf.read())!=-1)
            out.write(readBytes);
        
        }catch(Exception e){
        e.printStackTrace();
        }finally{
        if(out!=null)
            out.close();
        if(buf!=null)
            buf.close();
        }
很常见的代码,不知道问什么不行在JSP下
0 回复
1