struts1 파일 다운로드

	public ActionForward down(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//       
		//        
		//    get      ,     
		String name = new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");
		
		//         
		String path = request.getSession().getServletContext().getRealPath("/upload");
		//       , new FileInputStream
		//   response,          ,    response.getOutputStream()
		InputStream iStream = new FileInputStream(path+File.separator+name);
		OutputStream oStream = response.getOutputStream();
		
		//      response    
		//             
		response.addHeader("content-disposition", "attachment;filename="+java.net.URLEncoder.encode(name, "utf-8"));
		
		byte[] b = new byte[1024];//           iStream 
		int size = iStream.read(b);
		while (size > 0) {
			oStream.write(b,0,size);//       
			size = iStream.read(b);
		}
		iStream.close();
		oStream.close();
		return null;
	
	}
	

좋은 웹페이지 즐겨찾기