文件下载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(); }