You can't do that. JSP knowns nothing about HTML or JavaScript which are interpreted on the browser after the generated page is formatted and sent to the client, So how could JavaScript be used on the server in the JSP code before it even exists?
Please read
this article to understand how JSP operates and why that can never happen.
Then you can come back and describe
what you are trying to accomplish (rather than
how) and we can address how to best get it done.