String root = getServletContext().getRealPath( " / " ); String path = request.getParameter( " path " ); String name = request.getParameter( " name " ); response.setContentType( " unknown " ); response.addHeader( " Content-Disposition " , " filename=\ "" + name + " \ "" ); try { java.io.OutputStream os = response.getOutputStream(); java.io.FileInputStream fis = new java.io.FileInputStream(root + path + name); byte[] b = new byte[1024]; int i = 0; while ( (i = fis.read(b)) > 0 ) { os.write(b, 0, i); } fis.close(); os.flush(); os.close(); } catch ( Exception e ) { } 转载于:https://www.cnblogs.com/nanshouyong326/archive/2008/04/14/1153015.html