beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

JSTL <c:remove> Core Tag

By Chaitanya Singh | Filed Under: JSTL

<c:remove> tag is used for removing an attribute from a specified scope or from all scopes (page, request, session and application).

Example

In the below example, first I have set two variables using <c:set> tag and then I have removed one of them using <c:remove> tag. As you can see in the output screenshot – when I tried to display both the variables, for the second attribute the page didn’t get any value and printed the default value using default attribute of <c:out> tag.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Example of c:remove tag</title>
</head>
<body>
<c:set var="Site" scope="session" value="BeginnersBook.com"/>
<c:set var="author" scope="session" value="Chaitanya"/>
<c:remove var="author"/>
<a href="display.jsp">check attributes</a>
</body>
</html>

display.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="${Site}"/><br>
<c:out value="${author}" default="Attribute has no value"/>

c-remove-example

c-remove-example2

Scope attribute of <c:remove> tag

Above we have coded like this

<c:remove var="author"/>

This above code removes an attribute from all the scopes (page, session, application, request). In order to be specific we must need to specify the scope attribute inside <c:remove>  tag, like I did below – The below JSTL statement will remove the variable var from session scope.

<c:remove var="author" scope="session"/>

Enjoyed this post? Try these related posts

  1. JSTL <c:url> Core Tag
  2. JSTL <c:if> Core Tag
  3. fn:replace() – JSTL Function
  4. fn:join() and fn:split() JSTL Functions
  5. fn:toUpperCase() – JSTL Function
  6. fn:containsIgnoreCase() – JSTL Function

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSTL Core Tags

  • c:out
  • c:set
  • c:remove
  • c:if
  • c:choose
  • c:when
  • c:otherwise
  • c:catch
  • c:import
  • c:forEach
  • c:forTokens
  • c:param
  • c:url
  • c:redirect
JSTL Functions
  • fn:contains()
  • fn:containsIgnoreCase()
  • fn:indexOf()
  • fn:escapeXML()
  • fn:join() & fn:split()
  • fn:length()
  • fn:startsWith()
  • fn:endsWith()
  • fn:substring()
  • fn:substringAfter()
  • fn:substringBefore()
  • fn:trim()
  • fn:toUpperCase()
  • fn:toLowerCase()
  • fn:replace()

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap