I have a web application that currently hosts an applet in a web page. The applet connects to a Tomcat Servlet and sends requests. It would be more convenient for some environments if my solution could use Javascript instead of Java applets on the client. But this would require Javascript to send a POST to the Tomcat Servlet.
The web pages are served by the same web server – and actually the same Tomcat instance. But the applet sends requests to a DIFFERENT Servlet.
The Javascript basically would need to query the Servlet periodically and based on responses call a javascript function.
Would that be possible?
If so, any pointers on how to get started?
Yes, JavaScript can send POST requests to arbitrary web servers. If you have control of the servlet you can avoid all cross-site scripting restrictions by setting
access-control-allow-originproperties.AJAX is a term in the web community that refers to JavaScript + HTTP requests. I recommend this AJAX tutorial from MDN. I also recommend jQuery’s AJAX library.
Some versions of Internet Explorer will give you trouble even if the server is set up correctly. Here’s a JS function I use to cover all the browsers: