文件的上传,下载

下载
	
	public ActionForward downkey(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		String path=request.getSession().getServletContext().getRealPath(
		"/")
		+ "key/";
		
		String filepath = request.getParameter("path");
		
		response.setContentType("application/octet-stream");
		response.addHeader("Content-Disposition",
				"attachment;filename="+filepath);
		try {
			if (!"".equals(filepath)) {
				FileInputStream fis = new FileInputStream(path+filepath);
				ServletOutputStream sos = response.getOutputStream();
				int i = 0;
				while ((i = fis.read()) != -1) {
					sos.write(i);
				}
				fis.close();
				sos.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("报表下载发生异常:" + e.toString());
		}
		return null;
	}

你可能感兴趣的:(文件)