JSP學習筆記 - 內建對象 Response

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.