This post helps you understand and use the <c:remove> tag in the JSTL core tags library with code example.

The <c:remove> tag removes a scoped variable from its scope. We can specify the scope from where the variable to be removed. If no scope is provided, the variable will be removed from all the scopes.

 

JSTL <c:remove> Syntax:

<c:remove var="<string>" scope="<string>"/>

 

Attributes:

Name

Required

Type

Description

var

True

java.lang.String

Name of the scoped variable to remove from scope.

scope

False

java.lang.String

Scope where the variable can be found. (Optional)

 

JSTL <c:remove> Example:

The below example a variable into session scope and prints its value before and after removing it from the session scope.

<c:set var="userName" scope="session" value="Code Java"/>
<p>Before removing value from session: <c:out value="${userName}"/></p>
<c:remove var="userName"/>
<p>After removing value from session: <c:out value="${userName}"/></p>

 

Output:

remove-demo

 

Recommended Usage of JSTL <c:remove> tag:

This tag may be useful in cases where JSP can clean up any scoped variable it has set.

 

Other JSTL Core Tags:

if |  catch  |  choose   |  forEach  |  forTokens   |  import   |  out   |  param  |  redirect  |  set  |  url


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment