关于生成PDF文件 直接下载的问题? 请教大家

处理过程:
后台生成PDF
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		Document document = new Document(PageSize.A4, 36,36,36,36);
		ByteArrayOutputStream ba = new ByteArrayOutputStream();
		try{
			PdfWriter writer = PdfWriter.getInstance(document, ba);
			document.open();
			document.add(new Paragraph("Hello World"));
		}catch(DocumentException de){
			de.printStackTrace();
			System.err.println("A Document error:" +de.getMessage());
		}
		document.close();
		response.setContentType("application/pdf");
		response.setContentLength(ba.size());
		ServletOutputStream out = response.getOutputStream();
		ba.writeTo(out);
		out.flush();
	}


前台获取:
function getPDF()
{
	document.location.href="servlet/GetPDF";
}


问题是这样操作的话,pdf文件直接在浏览器上显示了,那如何直接提示用户下载到本地那?

你可能感兴趣的:(servlet,cache,浏览器)