客户端:
<script language="javascript" src="xmlhttp.js"></script>
<script language="javascript">
function clockFun(){
var url="TestTime.jsp";
xmlhttp.open
("get",url,true); //lxmlhttp对象在xmlhttp.js中声明;
xmlhttp.onreadystatechange=function(){ //指定服务器返回信息时客户端的处理程序
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){// http的状态码
document.getElementById("clock").innerHTML=xmlhttp.responseText;}}}
xmlhttp.send(null) ;}//发送请求到http服务器
function timer(){//计时器
window.setInterval('clockFun()',1000) ;}
</script>
服务器端(TestTime.jsp)
Calendar
beginTestTime=Calendarget Instance ();
beginTest Time.set(……);//省略号处为登录时间;
long
beginTime=beginTestTime.getTimeIn Millis();
long
nowTime=Calendar.getInstance().
get'TimeInMillis(); //获取当前时间
response.setHeader ("Cache -Control","no-cache");//数据不缓存
long hasTime=nowTime-beginTime;
//如用倒计时,此处要用总时长来减去此值;
response.getWriter().write ((new Long (hasTime/60000)).toString}+":"+(new Long((hasTime%60000)/1000)).toString}) ;//以文本方式返回时间 response.getWriter().flush();
3、试卷的定时存盘和预读试卷数据的实现。这两种功能的实现也采用Ajax技术,只是由于请求的数据量比计时器的数据量大,所以请求时采用“POST”方法。同时要求数据以xml格式返回,在客户端利用DOM的强大功能来实现对数据的操作。用“POST”,方法请求数据时客户端要添加Request头,xmlhttp.setRequestHeader ("Content-type","applicatior/ x-www-form-urlencoded");服务器端以xml格式返回数据时要设置Response响应头response..setContentType("text/xml"};这样返回客户端的数据才能以xml格式返回。
(三)系统测试
该系统测试的客户端为Internet Explore6.0和FireFox1.0,服务器端为Windows2003和RedHat AS4+JDK1.5+Tomcat5.5.9,网络环境为服务器在教育网内,客户机在局域网内和远程电信网。系统在局域网内部和广域网上的测试均达到了预期效果。
三、结束语
本文利用Ajax技术改进现有的网上考试系统,实现了在线考试的B/S系统,使其达到了C/S系统所具有的功能,同时兼备了B/S系统固有的优势,即能实现用户的网上在线考试的功能,又不需要用户安装额外的客户端软件。新的考试系统具有准确计时、快捷、安全、方便等优点,从根本上改变了原有网上考试系统的多种弊端。
参考文献:
1、Jesse James Garrett.Ajax: A New Approach to Web Applications[EB/OL].http: // adaptivepath. com/ publications/ essaysJarchives/000385.php,2006-02-28.
2、David Flanagan.JavaScript: The Detnitive Guide 4th Edition[M].0'Neilly Media,Inc,2001.
3、黄国平,陈斌.JSP与JavaScript整合使用[J].南通职业大学学报,2004(4).
基于AJAX技术提升Web考试系统性能的研究(2)
2012-08-21 20:40
基于AJAX技术提升Web考试系统性能的研究(2).doc
将本文的Word文档下载到电脑
下载失败或者文档不完整,请联系客服人员解决!