2016-05-20 15 views

答えて

0

次のJSPをコピーしてウェブアプリケーションに貼り付けてください。ブラウザの更新ボタンとページ上の更新リンクを使用して、ランダムにページを更新します。セッションスコープは、仕事をしなくてもWebアプリケーションを訪れている間、ユーザーデータを保存する場所を提供していることがわかります。リクエストパラメータは、現在のリクエストのデータのみを保持します。リクエストパラメータを使用してデータを保持するには、リクエストをサーバーに送信する必要があります。

${pageContext.session.setAttribute("count", count + 1)} 
If you refresh this page using your browser's refresh button, <br/> 
then you will increment the session-scoped variable "count" but not the request parameter "r".<br/> 
<a href="${pageContext.request.requestURL}?r=${param.r + 1}"> 
    Click here to refresh this page and increment the r parameter. 
</a><br/> 
If you use the above link to refresh this page, <br/> 
then you increment the r parameter by sending a new value in the query string. <br/> 
This page has been requested ${count} times in this session. <br/> 
The value of the r parameter in the current request is ${param.r eq null? "null" : param.r}  

古いサーバーを使用している場合は、スクリプトレットを使用する必要があります。

<% 
    Integer count = (Integer)session.getAttribute("count"); 
    if(count==null)count = new Integer(0); 
    session.setAttribute("count",new Integer(count.intValue() + 1)); 
%> 
If you refresh this page using your browser's refresh button, <br/> 
then you will increment the session-scoped variable "count" but not the request parameter "r".<br/> 
<a href="${pageContext.request.requestURL}?r=${param.r + 1}"> 
    Click here to refresh this page and increment the r parameter. 
</a><br/> 
If you use the above link to refresh this page, <br/> 
then you increment the r parameter by sending a new value in the query string. <br/> 
This page has been requested ${count} times in this session. <br/> 
The value of the r parameter in the current request is ${param.r eq null? "null" : param.r}  

リクエストスコープの変数は、ページで作成し、ページの他の場所にアクセスすることができます。要求が別のページに転送されている場合は、変数もそのページで使用できます。

${pageContext.request.setAttribute("message", "hello")} 
${message} 
関連する問題