1
Я хочу включить кнопку при подключении USB и отключить ее при удалении USB. Как я могу использовать ajax для изменения кнопки каждый раз, когда USB вставлен или удален?Как выполнить функцию ajax каждый раз, когда происходит смена сервлета?
Ajax
function loadXML(){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && 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();
}
Servlet- Как я могу отправить ответ на JSP каждый раз слушатель событий запускается и выполняет функцию АЯКС снова?
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();
}
}