文件下载java代码

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String filename=request.getParameter("filename");
		response.addHeader("content-Type", "applcation/octet-stream");
		response.addHeader("content=Disposition", "attachment;filename="+filename);
		InputStream inputStreamq=getServletContext().getResourceAsStream("/load/jj.jpg");
		OutputStream outputStream =response.getOutputStream();
		byte[]bytes=new byte[10];
		int len=-1;
		while((len=inputStreamq.read(bytes))!=-1) {
			outputStream.write(bytes,0,len);
		}
		outputStream.close();
		inputStreamq.close();
	}

 

posted @ 2018-12-24 16:04  黑魔法os  阅读(159)  评论(0编辑  收藏  举报