1. 程式人生 > >java中response.setHeader()

java中response.setHeader()

一秒重新整理頁面一次 response.setHeader("refresh","1");

 二秒跳到其它頁面 response.setHeader("refresh","2;URL=otherPagename");

沒有快取:
response.setHeader("Pragma", "No-cache");
  response.setHeader("Cache-Control", "no-cache");

設定過期的時間期限  
  response.setDateHeader("Expires", System.currentTimeMillis()+自己設定的時間期限);

訪問別的頁面:response.setStatus(302); response.setHeader("location","url");

通知瀏覽器資料採用的壓縮格式:response.setHeader("Content-Encoding","壓縮後的資料"); 
快速瀏覽器壓縮資料的長度:response.setHeader("Content-Length",壓縮後的資料.length+"");

快速瀏覽器圖片或視訊:response.setHeader("Content-type","這個引數在tomcat裡conf下的web.xml裡面找");

inputstream in= this.getServletContext.getResourceAsStream("/2.jpg");
int len=0;
byte buffer[]= new byte[1024]

outputStream out = response.getOutputStream();

while(len=in.read(buffer)>0){
  out.write(buffer,0,len)
}


快速瀏覽器已下載的形式:response.setHeader("Content-disposition","attachment;filename=2.jpg");

inputstream in= this.getServletContext.getResourceAsStream("/2.jpg");
int len=0;
byte buffer[]= new byte[1024]

outputStream out = response.getOutputStream();

while(len=in.read(buffer)>0){
  out.write(buffer,0,len)
}