You can do this by passing the value of the servlet as HTML-JavaScript content, and then access that tag in the script tag.
You can try the following: In the Servlet method
PrintWriter out = response.getWriter (); out.print ("var xyz = 20;");
In the HTML page
Inside the script tag:
var abc = xyz;
But you will need to execute the servlet on the HTML page. In tomcat, if you have a servlet mapping, just type:
"<\ script src =" / servlet -name "> </script>
source
share