I am trying to manually set values of variables using jstl syntax.
<c:set var="var1" value="2"/>
<c:set var="var2" value="2"/>
<c:set var="var3" value="2"/>
<c:set var="var4" value="2"/>
<c:set var="var5" value="2"/>
<c:set var="var6" value="2"/>
The above syntax works.. But I am curious as to why the below syntax does not.
<c:forEach var="myVar" start="1" end="6">
<c:set var="Display${myVar}" value="2"/>
</c:forEach>
Why cant we set variable names dynamically in jstl unlike other languages. Is there a smarter way?
Here a working code example:
Result:

This example uses the page context/scope, which is the default. Of course all contexts/scopes available (page, request, session, application) can be used, if needed.