1、首页部分:
<body onload="init('<%=ses_userBean.getUsername()%>');"> // load时调用init(user);
2、js部分:xmlhttp实现页面局部刷新,调用check_mail.jsp对后台数据库进行检索判断并返回结果:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var checkresult=null;
var username =null;
function init(user){
username=user;
window.setInterval('Checkmail()',5000);//每隔5秒自动调用Checkmail()
}
function Checkmail()
{
xmlhttp.open("POST", "check_mail.jsp?uName="+username, false);
xmlhttp.onreadystatechange = updatePage;
xmlhttp.send();
}
function updatePage() {
if (xmlhttp.readyState < 4) {
test1.innerHTML="loading...";
}
if (xmlhttp.readyState == 4) {
var response = xmlhttp.responseText;
if(response==1){ //判断为假
test1.innerHTML=" ";
checkresult=1;
}
else{ //判断为真
test1.innerHTML="<img alt='新邮件' src='img/tp024.gif'><EMBED src='music/nudge.wma' hidden=true autostart=true loop=false>";
checkresult=0;
}
}
}
3、check_mail.jsp用于处理科幻段发送上来的请求,并返回对数据库查询得到的结果,有加过返回0,无结果返回1.
<%@