[英]Show java servlet process in web
我正在开发一个小型Web应用程序,该应用程序查询几个数据库以进行数据预测,然后返回具有预测结果的对象。
这已经有些工作了,但是servlet中的数据处理可能会超过半小时,具体取决于查询过滤器,我通常在Submit上设置一个javascript“加载” div,但是有点遗憾。
所以问题是,在处理servlet时,我是否可以以某种方式将消息发送到Web客户端,以使页面看起来好像不死了? (使用有关该过程进行情况的实际信息来改善加载div)
只需在发送请求之前添加预加载器,并在成功后删除该预加载器即可。
var isBool = false;
function communicateWithServer(){
$("#preloader").show();
var isBool = false;
$.ajax({
url : 'url',
data : {
},
type : 'POST',
dataType : 'text',
success : function(response) {
isBool=true;
$("#preloader").hide();
//Show success
},
error : function(request, textStatus, errorThrown) {
$("#preloader").hide();
//show error
}
});
secondComm();
}
function secondComm(){
$.ajax({
url : 'url2',//send the response from your second servlet to this
data : {
},
type : 'POST',
dataType : 'text',
success : function(response) {
$("#preloader").text(response.value);
if(!isBool){secondComm();}
//
},
error : function(request, textStatus, errorThrown) {
if(!isBool){secondComm();}
//show error
}
});
}
请不要与jquery
混淆,您也可以在没有jquery
情况下执行此操作。
function communicateWithServer() {
document.getElementById("preloader").style.display = 'block';
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//show success
} else {
//show error
}
document.getElementById("preloader").style.display = 'none';
};
xhttp.open("GET", url, true);
xhttp.send();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.