標籤:ade header 第一個 war direct length forward 代碼執行 時間
1.response.addHeader("refresh","2"); 制定頁面重新整理時間
2.response.addHeader("refresh","2,hello.html"); 制定一段時間後的頁面跳轉,此跳轉url將改變,為用戶端跳轉
3.response.sendRedirect("hello.html");用戶端跳轉
<jsp:forward page="hello.html"/>為伺服器段跳轉
區別在於:用戶端跳轉 request設定的屬性將無法保留,伺服器段可以。
用戶端跳轉是在所有程式碼執行完才進行,伺服器跳轉是立即進行,如果要關閉JDBC需要再伺服器跳轉之前進行。
a. 用戶端跳轉,兩個println語句打完之後,頁面才會跳轉
<%System.out.println("---------------跳轉之前----------------------");
response.sendRedirect("hello.html");
System.out.println("---------------跳轉之後----------------------");%>
b.伺服器跳轉,只打出第一個println,之後就會跳轉
<%System.out.println("---------------跳轉之前----------------------");%>
<jsp:forward page="hello.html"/>
<% System.out.println("---------------跳轉之後----------------------");%>
4.Cookie操作
向用戶端發送cookie
Cookie c1 = new Cookie("username","jack");
c1.setMaxAge(300);// 以秒來計數
response.addCookie(c1);
用戶端如何擷取cookie
Cookie c[] = request.getcookies();
for(x=0;x<c.length;x++){
<%=c[x].getName()%>----------->
<%=c[x].getValue()%>
<br>
}
JSP學習筆記 - 內建對象 Response