如何在 JSP 中從當前作用域中移除 Java 變數?


<c:remove> 標籤從指定的範圍或者從找到該變數的第一個範圍(如果沒有指定範圍)中移除一個變數。此操作並沒有什麼特別幫助,但是可以幫助確保 JSP 清理了它所負責的任何範圍資源。

屬性

<c:remove> 標籤具有以下屬性 −

屬性描述是否必需預設值
var要移除變數的名稱
scope要移除變數的作用域所有範圍

示例

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<html>
   <head>
      <title><c:remove> Tag Example</title>
   </head>
   <body>
      <c:set var = "salary" scope = "session" value = "${2000*2}"/>
     <p>Before Remove Value: <c:out value = "${salary}"/></p>
     <c:remove var = "salary"/>
     <p>After Remove Value: <c:out value = "${salary}"/></p>
   </body>
</html>

以上程式碼會生成以下結果 −

Before Remove Value: 4000
After Remove Value:

更新於:30-Jul-2019

396 次瀏覽

開啟您的 職業

完成課程,獲得認證

馬上開始
廣告
© . All rights reserved.