JSPs are interpreted by the server before outputting to the browser, so your tags are interpreted before serving them in the browser. In a standard JS configuration, files are not interpreted by the server, but simply transferred to the client as plain text.
If you want to dynamically create JS with JSP (as in your example), you need to make the server interpret the file before serving it to the client. The easiest way is to place the contents of the JS in a JSP file. Then on the html page, a script is included with the script tag and the src attribute is equal to your.jsp, for example. <script src = "script.jsp" </script>
source share