JSTL Core Tag remove Example

JSTL Core Tag remove Example


Posted in : Java Posted on : April 1, 2012 at 6:47 PM Comments : [ 0 ]

In this tutorial you will learn about how to use the JSTL core variable support tag remove in JSP.

JSTL Core Tag remove Example

In this tutorial you will learn about how to use the JSTL core variable support tag remove in JSP.

JSTL provides the <c:remove> tag to remove the value associated with the variable. This tag deletes the variable from the specified scope. But in case of the scope is not specified it deletes the variable from the first scope where it is found.

Attributes of remove tag :

Following attributes may used with the remove tag :

  • var : This attribute is used to define the name of variable that is required to remove.
  • scope : This attribute is used to specify the variable's scope from where it is required to remove. If the scope is not specified for the removed variable then the attribute is removed from the first scope where it is found.

Example :

Here we are giving a simple example to demonstrate you about how to use the <c:remove> tag in jsp. In the example is being given below I have first set the value of a variables using <c:set> tag and then removed the one value using <c:remove> tag of JSTL core tag library. So as an output you will see the values that I set to variables 'str' & 'str1' but in the further step you will see there is only value is retained and the other value is removed. It is happened because I removed the value of the variable 'str1' using <c:remove var="str1" />

JstlCoreTagRemoveExample.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>JSTL Example</title>
</head>
<body>
<h3>JSTL Core Tag remove Example.</h3>
<c:set var="str" value="Dev"/>
<c:set var="str1" value="Manuals" />
<h4>Values of the associated variables are ....</h4>
<b>Value of str : </b><c:out value= "${str}" /><br>
<b>Value of str1 : </b><c:out value= "${str1}" /><br> 
<!-- Removing the value associated to variable str1 -->
<c:remove var="str1"/>
<h4>After Removing the value of str1 variable ....</h4> 
<b>Value of str : </b><c:out value="${str}" /><br>
<b>value of str1 : </b><c:out value="${str1}" /><br>
</body>
</html>

How to Run this example

Here I am using an IDE Eclipse so I am giving the process of executing this example in perspective of Eclipse. Before executing this example you will have needed to add the following jar files :

  • jstl.jar
  • standard.jar

After adding of these jar files you may execute your program in the following ways :

  • Select JstlCoreTagRemoveExample.jsp page of your project in Project Explorer -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • On the Eclipse Editor go to your JstlCoreTagRemoveExample.jsp -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • Go to Run button look at the toolbar in green color and click -> Choose your server -> Finish.
  • A simplest way to execute the example in Eclipse is to use the CTRL+F11 key -> Choose your server -> Finish

NOTE : In all of the above execution processes you may start the server first and stop the server each time after the execution if not, each time you will may prompted to a dialog box to Restart the server in Eclipse.

Output :

When the execution process will be completed successfully an output will be displayed on your eclipse browser as :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics