jsp页面文件下载

<%@ page language="java" pageEncoding="utf-8"%>
<%@ page  import="java.io.*" %>

<%

	BufferedInputStream bis = null;
	BufferedOutputStream bos = null;
	
	try{
        String   filename="InstallClient.zip";   
	    response.setContentType("application/x-msdownload");   
	    response.setHeader("Content-Disposition","attachment;   filename=\""   +   filename   +   "\"");   
	      
		bis =new java.io.BufferedInputStream(new java.io.FileInputStream(config.getServletContext().getRealPath("/" + filename)));
		bos=new java.io.BufferedOutputStream(response.getOutputStream()); 
		byte[] buff = new byte[2048];
		int bytesRead;
		while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
	
		bos.write(buff,0,bytesRead);
		}
	}
	catch(Exception e){
		e.printStackTrace();
	}
	finally 
	{
		if (bos != null)
		{
			bos.close();
		}
		if (bis != null)
		{
			bis.close();
		}
		out.clear();
		out = pageContext.pushBody();
	}
	%>

你可能感兴趣的:(java,html,jsp)