编程论坛's Archiver

macrossyun 发表于 2008-7-5 13:34

关于下载页面的制作

我做了个下载的界面,可是在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下

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.