https://coderanch.com/t/414294/JSP/java/scriptlets-Vs-EL-JSTL
https://coderanch.com/t/292479/JSP/java/JSTL-vs-Scriptlet-again
You should not put stuff like that in JSP.
To maintain a good architectural separation of ui, business logic, db, and others if any, scriptlets should be moved to tags to cleanly separate the business logic on those.
If you are making only a few jsps, or you are not the one who will maintain those jsps you are making, go ahead and use scriptlets (and hope the maintainer is not a chain saw murderer).
Let me give you one example.
I recently made a custom tag that returns
struts' current module context. After that, I used that tag in tens of jsps. Imagine, how clean that is. Just 1 line. And if I need to change the functionality of such thing, I only change the tag java code and all jsps receives the change.
I dont blame you. I also felt the same way before, until I actually worked on systems that use hundreds of jsps and
servlets.