<%@ page import="java.io.*,java.util.*;" %>
<%
    String downloadFile = "C:\\boot.ini";
    BufferedInputStream inputstream = new BufferedInputStream(new
        FileInputStream(downloadFile));
    response.setContentType("application/octet-stream");
    response.addHeader("Content-Disposition",
                       "attachment; filename=\"write.ini\"");
    response.setHeader("Accept-ranges", "bytes");
    byte[] b = new byte[100];
    int len;
  OutputStream outp=response.getOutputStream();
try{
    while ( (len = inputstream.read(b)) > 0) {
    outp.write(b, 0, len);;
    }
    inputstream.close();
outp.close();}
catch(Exception e){
  e.printStackTrace();
outp.close();
}
%>

解决方案 »

  1.   

    客户端要用activeX写,安全问题
      

  2.   

    就象下载一样做,如果客户端不需要保存也可以cancel,呵呵
      

  3.   

    对,客户端不可能就无声无息地保存(下载)服务端的文件的,这些都是安全问题。客户端可以写个activeX,然后调用
      

  4.   

    <%@ page import= "java.io.*,Common.CodeConvert" %><%
        try{
            //取得虚拟的路径
            String vpath = CodeConvert.UnicodeToChinese(request.getParameter("path"));
            String vname = CodeConvert.UnicodeToChinese(request.getParameter("name"));
            String extendName = null;
            String realpath = null;
            if( vpath.indexOf(":") == -1 ){
            //取得真实路径
                realpath = getServletConfig().getServletContext().getRealPath("") + vpath;
            }
            else{
                realpath = vpath;
            }
            extendName = vpath.substring(vpath.lastIndexOf("."));
            if( vname == null || vname.equals("") ){
                vname = vpath.substring(vpath.lastIndexOf("/")+1);
            }else{
                vname += extendName;
            }
            String fn = "attachment; filename="+vname;  //必须改为UniCode编码的字符串
            System.out.println(fn);
            //把标题、内容写到输出流中
            response.setHeader("Content-Disposition", new String(fn.getBytes("GB2312"),
                                            "ISO-8859-1"));
            createOutput( response.getOutputStream(),realpath);
        }catch( Exception ee ){
            ee.printStackTrace();
        }
    %><%!
    public void createOutput( OutputStream out,String realpath ) throws IOException {
        int b;
        BufferedInputStream  m_input =
                    new BufferedInputStream( new  FileInputStream(realpath) );
        while( (b = m_input.read()) != -1 ){
            out.write(b);
        }
        m_input.close();
        out.flush();
        out.close();
    }
    %>现正使用的