Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to execute an ajax function everytime there is a change in the servlet?
    text
    copied!<p>I want to enable the button when a USB is inserted and disable it when the USB is removed. How can I use ajax to change the button everytime the USB is inserted or removed?</p> <p>Ajax</p> <pre><code>function loadXML(){ var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { alert (xmlhttp.responseText); if(xmlhttp.responseText == "true") { document.getElementById('scan').disabled=false; } else { document.getElementById('scan').disabled=true; } } } xmlhttp.open("GET", "ScanJobServlet", true); xmlhttp.send(); } </code></pre> <p>Servlet- How can I resend the response to JSP everytime the event listener is triggered and perform the ajax function again?</p> <pre><code> public static boolean status = false; protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub //super.doGet(req, resp); PrintWriter out = resp.getWriter(); RemovableStorageEventListener listener = new RemovableStorageEventListener() { public void inserted(Storage storage) { status = true; } public void removed(Storage storage) { status = false; } }; BundleContext bc = AppManager.getInstance().getBundleContext(); StorageManager sm = StorageManager.getInstance(KSFUtility.getInstance().getApplicationContext(bc)); sm.addListener(listener); if (status==true) { out.print("true"); } else { resp.reset(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload