下载的源程序

 

<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.File" %>
<%

    StringBuffer sb = new StringBuffer();
    String path = request.getSession().getServletContext().getRealPath("index.jsp");
    out.println(path);

    ServletOutputStream outPut = response.getOutputStream();
    if (path != null)
    {
        response.setContentType("application/force-download");
        response.setHeader("Content-Disposition", "attachment;filename=\"" + "index.jsp" + "\"");
        FileInputStream in = new FileInputStream(new File(path));
        int length = 0;
        byte[] buf = new byte[512];
        if (in != null)
        {
            while (((length = in.read(buf)) != -1))
            {
                outPut.write(buf, 0, length);
            }
            outPut.flush();
        }
    }
%>

相关帖子:
  • No Related Posts
  • micas Nov 13th 2005 09:36 pm J2EE No Comments yet Trackback URI Comments RSS

    Leave a Reply

    You must be logged in to post a comment.