Jfreechart+ajax 实现动态仪表图 jsp


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <script>
	function makeRequest(url) {
		 http_request = false;
		 if (window.XMLHttpRequest) {
		  http_request = new XMLHttpRequest();
		  if (http_request.overrideMimeType){
		   http_request.overrideMimeType('text/xml');
		  } 
		 }else if(window.ActiveXObject) { 
		    http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
		 } 
		 if (!http_request) {
		  alert("需要 IE 5.0 以上版本!");
		  return false;
		 }
		 var url="servlet/DialServlet";
		 http_request.onreadystatechange = init; 
		 http_request.open('GET', url, true); 
		 http_request.setRequestHeader("If-Modified-Since","0"); 
		 http_request.send(null);
		 setTimeout("makeRequest('"+url+"')",4000);
	}
	function init() { 
			 if (http_request.readyState == 4) {
				  if (http_request.status == 0 || http_request.status == 200) {
				   var result = http_request.responseText;
					   if(result==""){
					    result = "ͼ";
					   }
				   var time = new Date();
				   var img=document.getElementById ("img");
				   img.src="<%=basePath%>"+"WarnImages/meter.jpeg?"+time.getTime();
				  	}else {}
			 }
	    
	}
  </script>
</head>
  
  <body>
    <table>
		<td colspan="2" align="center"> 
        	<div>
        		<img src="" id="img" width="200" height="200" border="0" >
        	</div>
        </td>
</table> <br>
  </body>
</html>

<script>
window.onload(makeRequest("servlet/DialServlet"));
</script>





你可能感兴趣的:(java,jsp,Ajax,jfreechart,IE)