JSTL c:set Example

JSTL c:set Example explains about How to use c:set tag inside JSTL for defining a variable
Consider an example, where you need to define a variable and store some values into that variable, In that case you can use JSTL c:set Example
c:set is available as a part of JSTL core tags, this tag evaluates an expression and can be set to a variable, so that we can reuse that variable in other places
Inside c:set tag, we can also customize the scope of the variable whether it is for page,request,session or application.
You can see the below demonstrating the usage JSTL c:set Example inside JSTL
Required Libraries
JSTL c:set Example
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <html> <head> <title>JSTL c:set Example</title> </head> <body> <!-- JSTL c:set Example --> <p> <c:set scope="request" value="Rockey" var="name" /> <c:set scope="session" value="25" var="age" /> <c:set scope="application" value="C/3343" var="address" /> <c:set value="Delhi" var="city" /> <c:out value="${age}" /> <c:out value="${name}" /> <c:out value="${address}" /> <c:out value="${city}" /> </p> </body> </html>
Output
25 Rockey C/3343 Delhiyou can also use c:set on the following ways