Why does almost all the Java based web development framework use "template" system, instead of generating HTML from code(like Flutter/Swift)? Is this due to the inherent limitation of Java language/syntax?
Swift has function builders which are part of the magic that makes such DSLs practical.
In Kotlin, which also runs on the JVM, this is possible much more easily than in Java: https://kotlinlang.org/docs/typesafe-html-dsl.html
At the relative bottom (Servelet API level) it works that way, servlets have a direct access to input/output stream, and they have to write plain byte[] (or string via Writer).
As for java syntax, it's not great for string manipulation, encoding (you will need some functions for all the html/javascript escaping).
If you see url's containing ".do" extensions - that was the standard for calling servlets w/o anything, it has changed, of course.