文章詳情頁
jsp Response對象頁面重定向、時間的動態(tài)顯示
瀏覽:207日期:2022-06-08 08:39:20
Response對象
response對象主要用于對客戶端的請求進行回應,將web服務器處理后的結(jié)果發(fā)回給客戶端,封裝了jsp產(chǎn)生的響應,并發(fā)送到客戶端響應客戶端的請求,請求的數(shù)據(jù)可以是各種數(shù)據(jù)類型,甚至是文件。
常用的方法:void addCookie(Cookie c)
添加一個Cookie對象,用來保存客戶端用戶信息。
比如一些登錄操作是否記住用戶名等等。void setHeader(String name,String value)
常用的有刷新操作和定時跳轉(zhuǎn)頁面。
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") //幾秒后跳轉(zhuǎn):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> <% /* *在瀏覽器進行重定向。跳轉(zhuǎn)時機,當頁面代碼執(zhí)行完畢, *把響應發(fā)送給客戶端之后,客戶端再根據(jù) *重新指向的url地址。瀏覽器地址欄中的地址是改變的 */ response.sendRedirect("response3.jsp"); %> </body> </html>
跳轉(zhuǎn)的頁面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>重定向后的內(nèi)容</title> </head> <body> <h1>重定向后的頁面</h1> </body> </html>
到此這篇關于jsp Response對象頁面重定向、時間的動態(tài)顯示的文章就介紹到這了,更多相關jsp Response頁面重定向內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持!
標簽:
JSP
相關文章:
排行榜
