response向客户端输出的两种方式

1. response.getOutputStream() 

输出字节流, 客户端会下载字节流并生成文件保存本地

response.setHeader("Content-disposition", "attachment;filename= ***.**");  //客户端得到的文件名
response.setContentType("application/x-download");//设置为下载application/x-download  	
response.setContentType("text/html; charset=UTF-8");   
response.setHeader("Cache-Control","no-cache");   
response.setHeader("Cache-Control","no-store");   
response.setDateHeader("Expires", 0);   
response.setHeader("Pragma","no-cache"); 
OutputStream fos = response.getOutputStream();
fos.write("hello".getBytes());

2. response.getWriter();

直接在页面上输出字符串

PrintWriter pw = response.getWriter();
pw.println("hello");
pw.flush();
pw.close();


你可能感兴趣的:(JAVA)