java下载

public ActionForward downloadDocFile(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		String recordId = request.getParameter("recordId");
		Integer docRecordId;
		try {
			docRecordId = new Integer(recordId);
		} catch (Exception e) {
			docRecordId = null;
		}
		if (docRecordId != null) {

			CamDoc cd = camDocControl.findByRecordID(new Integer(recordId));

			byte[] doc = cd.getDocObject();

			response.setContentType("application/octet-stream; charset=GBK");
			response.setContentLength(doc.length);
			response.setHeader("Content-disposition",
					"attachment; filename="
							+ new String(cd.getFileName().getBytes("GBK"),
									"ISO-8859-1"));
			response.getOutputStream().write(doc);

		}
		return null;
	}

你可能感兴趣的:(下载)