How can I invoke a servlet from JavaScript?

Nicola Ken Barozzi

Yes, and it is quite easy. You just have to remember that a servlet is seen by the browser like a normal web page with its URL. Just call it lke you would call a web page. It is also possible to use servlet data in javascript without changing page. For example I am using Microsoft XML data islands that get XML data from a servlet.


    function display()
      data.transformNodeToObject(ss.XMLDocument, resultTree.XMLDocument);
  <SCRIPT FOR="window" EVENT="onload">
    data.async = false;
    ss.async = false;
  <XML id="data"></XML>
  <XML id="ss"></XML>
  <XML id="resultTree"></XML>

Here "../servlet/SQLResult" is a servlet URL.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.