Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình

Cách xóa biến Java khỏi scope hiện tại trong JSP

Tag <c:remove> xóa biến khỏi scope chỉ định hoặc scope đầu tiên tìm thấy biến (nếu không chỉ định scope). Hành động này hỗ trợ dọn dẹp tài nguyên scope mà JSP chịu trách nhiệm.

Thuộc tính

AttributeDescriptionRequiredDefault
varTên biến cần xóaYesNone
scopeScope của biến cần xóaNoAll scopes

Ví dụ

<%@ taglib uri = "https://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>

Kết quả:

Before Remove Value: 4000
After Remove Value: