You need to understand the difference between scriptlets and jstl
Scriptlets :
scriptlets are transformed into a Java codes and are compiledwhen service method of the JSP is called.
JSTL tags :
Attributes, and by default are scoped at the page context level. As a result, if you need to pass value in a scriptlet to jstl, you can do so by calling the setAttribute() method on the appropriately scoped object (usually pageContext and request)
JSTL works entirely with scoped attributes, either at page, request or session scope
So look here How to avoid Java code in JSP files?
Hope this helps !!