jsp Response對象頁面重定向、時間的動態(tài)顯示
response對象
response對象主要用于對客戶端的請求進行回應,將web服務器處理后的結果發(fā)回給客戶端,封裝了jsp產生的響應,并發(fā)送到客戶端響應客戶端的請求,請求的數(shù)據(jù)可以是各種數(shù)據(jù)類型,甚至是文件。
常用的方法:void addcookie(cookie c)
添加一個cookie對象,用來保存客戶端用戶信息。
比如一些登錄操作是否記住用戶名等等。void setheader(string name,string value)
常用的有刷新操作和定時跳轉頁面。
response.setheader(“refresh”,“1”),response.setheader(“refresh”,“2:url=xxx”)。
void sendredirect(string url)設置頁面重定向。
舉例1:時間動態(tài)顯示
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <%@ page import="java.util.*"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>日期的更新</title> </head> <body> <% //void setheader(string name,string value) //功能:常用的刷新refresh,例如:response.setheader("refresh","1") //幾秒后跳轉:response.setheader("refresh","2:url=xxx") date now = new date(); out.print(now.tolocalestring()); response.setheader("refresh", "1");//一秒刷新一次 %> </body> </html>
頁面的重定向:
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>頁面重定向</title> </head> <body> <% /* *在瀏覽器進行重定向。跳轉時機,當頁面代碼執(zhí)行完畢, *把響應發(fā)送給客戶端之后,客戶端再根據(jù) *重新指向的url地址。瀏覽器地址欄中的地址是改變的 */ response.sendredirect("response3.jsp"); %> </body> </html>
跳轉的頁面
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>重定向后的內容</title> </head> <body> <h1>重定向后的頁面</h1> </body> </html>
到此這篇關于jsp response對象頁面重定向、時間的動態(tài)顯示的文章就介紹到這了,更多相關jsp response頁面重定向內容請搜索碩編程以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持碩編程!