JSP中Request屬性範圍

2021-06-26 12:05:34 字數 1596 閱讀 3355

通過新增引數,通過來實現伺服器端跳轉,以此來測試request屬性的範圍:

步驟一:requestscopedemo.jsp (新增info1引數)———>通過跳轉

步驟二:requestscopedemo_1.jsp (新增info2引數)———>通過跳轉

步驟三:requestscopedemo_2.jsp (request物件中取info1、info2兩個引數的值)

requestscopedemo.jsp :

//想輸入乙個字串「」不能直接輸出必須通過轉義輸出

string info1="page 1 頁面中新增()的引數 !";

request.setcharacterencoding("utf-8");

%>

" />

requestscopedemo1.jsp :

string info2="page 2 頁面中新增()的引數 !";	

%>

info引數:

" />

requestscopedemo2.jsp :

/*request物件的源頭設定了編碼,所以這裡就不需要設定啦*/

通過來request.setattribute()新增引數,通過來實現伺服器端跳轉,以此來測試request屬性的範圍:

步驟一:

requestscopedemo_t.jsp (新增info1引數)———>通過跳轉

步驟二:

requestscopedemo_t1.jsp (新增info2引數)———>通過跳轉

步驟三:

requestscopedemo_t1.jsp (request物件中取info1、info2兩個引數的值)

requestscopedemo_t.jsp :

request.setcharacterencoding("utf-8");

request.setattribute("info1","page1中新增(setattribute)的引數");

%>

requestscopedemo_t1.jsp :

request.setattribute("info2","page2中新增(setattribute)的引數");

%>

跳轉中的頁面,info1引數:

request屬性在伺服器端跳轉時request相當於是乙個訊息資訊在各個頁面中傳遞,各個頁面是共享同乙個request物件。

JSP屬性範圍

request就是伺服器跳轉之後還可以使用,伺服器跳轉就是jsp forward啦 特徵就是url不會改變 session就是伺服器跳轉,客戶端跳轉之後都可以使用 這兩種相當於public屬性 下面是例子 設定page屬性 pagecontext.setattribute name huang pa...

JSP屬性範圍

在 jsp中提供了 4 中屬性範圍 他們分別是page request session 和。對這幾個作用範圍的說明如下 page 範圍 指所設定的屬性盡在當前頁面內有效。使用 pagecontext 的setattribute 方法可以設定屬性值,使用 pagecontext 的getattribu...

JSP中4中屬性的儲存範圍

1 page 只在乙個頁面中儲存屬性,跳轉後無效。2 request 只在一次請求中儲存屬性,伺服器跳轉後依然有效。3 session 在一次會話範圍中儲存,無論何種跳轉都可以使用,但是新開的瀏覽器無法使用。其操作方法如下 setattribute name 李明 設定屬性的名稱及內容。getatt...