Is it possible to achieve what you are attempting?
The simple answer is NO...
Let's explore the reason behind this. Take a clue from JSTL (JavaServer Pages Standard Tag Library).. notice the word 'Server'. Yes.
JSP pages undergo compilation similar to Java files. Once successfully compiled, they are sent as a response which is then rendered by the browser for display.
JavaScript: a client-side programming language where codes are executed by the browser rather than the server.
During compilation of a Jsp file, only the Scriptlet and JSTL parts are considered while the rest of the code (HTML, CSS, JS) is treated as text.
Now, imagine a scenario in your code where the Java compiler encounters myFunc
, assuming it must be a method but not finding any reference.
Since Javascript functions can only run on the browser side, Java cannot recognize myFunc
, resulting in an unknown variable cls
.
This explanation sheds light on how JSP and Server Side processes work together.
So, keeping these factors in mind, brainstorm alternative solutions to tackle your issue.
Happy Coding :)