Each servlet response is basically an Http doc / snippet document. This way you can return a javascript function call that will be executed on the client side. The function may be passed in response to the Servlet or may be pre-included in the .js file.
just an example:
PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.println("<script type=\"text/javascript\">");
out.println("alert('deadbeef');");
out.println("</script>");
source
share