<c: set>
2. <c: set>
The <c:set> tag is JSTL-friendly version of the setProperty action. The tag is helpful because it evaluates an expression and uses the results to set a value of a JavaBeans or a java.util.Map object.
Attributes :
The attributes of <c: set> are
1. Value : Information to save
2. Target : Name of the variable whose property should be modified
3. Property : Property to modify
4. var : Name of the variable to store information.
5. scope : Scope of variable to store information
Form1: To set an attribute in any scope.
Syntax:
<c:set var = “name of attribute” value = “value of attribute” scope = “session”/> |
Note : var and value attributes are mandatory but scope attribute is optional.
default scope is page.
test.jsp
<%@ page isELIgnored="false" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <c:set var="x" value="10" scope="session"></c:set> <c:set var="y" value="20" scope="session"></c:set> <c:set var='z' value="50" scope="session"></c:set> <h3>Addition :<c:out value="${x+y+z}"></c:out></h3> <h3>subtraction :<c:out value="${z-y-x}"></c:out></h3> <h3>multiplication :<c:out value="${x*y*z}"></c:out></h3> |
No comments:
Post a Comment