问题是这样的,我在一个页面用onload的函数掉用AJAX脚本去数据库中取一些记录回来,在用document.write()打印到本页,可这样,这页面运行正常,但运行15次的时候就会停止响应,页面什么都取不到了,这是为什么呢?下面是我的代码?大家请看:<%@ page language="java" pageEncoding="GB2312"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    
    <title>showstuff.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--><script>var req;function createXMLHttpRequest(){   if (window.XMLHttpRequest) {      req = new XMLHttpRequest();    }else if (window.ActiveXObject) {      req = new ActiveXObject("Microsoft.XMLHTTP");    } }function getResult(state) {
   var url = "showstuff?state="+state+"&data="+new Date().getTime(); //data数据为了处理输入框有时输入相同信息Ajax不跳转问题,后台并未对此数据操作
      createXMLHttpRequest();
    
 
   if(req){ 

     req.open("GET",url, true);      req.onreadystatechange = complete; //调用complete()方法

     req.send(null);    } 
 } function complete(){   if (req.readyState == 4) { 
 alert("4");
    if (req.status == 200) {  var a=req.responseText;
document.write("<META http-equiv='Content-Type' content='text/html; charset=GB2312' /> <style type='text/css'> p{font-family:宋体; font-size:13px;} li{font-family:宋体; font-size:13px;}</style> <body background='../images/bj31.jpg' style='background-repeat: repeat-x; background-attachment:fixed;' >"+a);
   } 
   }   }</script>  </head>  <body onload="getResult(<%=request.getParameter("id") %>)"> //取上一页传过来的参数ID来判断取那条记录
}
 <br>
  </body>
</html:html>

解决方案 »

  1.   

    第15次就是不调用 onload的方法了,其它的都一样!
      

  2.   

     onload 方法没问题,右键新窗口中打开就好用! 在本窗口中打开就不好用,本窗口是一个iframe ,后台取数据库代码也没问题呀,大家看: String state = request.getParameter("state");
    String english = request.getParameter("english");
    if(english!=null && !english.equals("")){
    long id = 0;
    if (!state .equals("null")) {
    id = Long.parseLong(state); Matter1DAO dao = (Matter1DAO) WebApplicationContextUtils
    .getWebApplicationContext(this.getServletContext())
    .getBean("Matter1DAO");
    List list = dao.findByProperty("cid", id);

    Matter1 matter1 = null;
    if (list.size() != 0 && list != null) {
    matter1 = (Matter1) list.get(0);
    String str = matter1.getSContent();
    PrintWriter out = response.getWriter(); out.write(str); out.close();
    }
    }
    很简单啊,不能出问题呀
      

  3.   

    看了下代码
    没发现你的定时器
    就是说你只有在打开页面的时候调用了一次该方法,然后请求处理页面再返回结果
    也许是超时就没response了在onload的函数里写一个定时器  调用就可以了
      

  4.   

     数据库操作应该没有问题的,因为其它部份都是一样的,就没有问题,就是这个窗口onload不执行了,但右键另要开窗口就好用,我疯了。
      

  5.   

    private java.util.Timer timer;timer = new Timer(true);timer.schedule(new java.util.TimerTask() { public void run(){ //server.checkNewMail(); 要操作的方法} }, 0, 5*60*1000);第一个参数是要操作的方法,第二个参数是要设定延迟的时间,第三个参数是周期的设定,每隔多长时间执行该操作。使用这几行代码之后,Timer本身会每隔5分钟调用一遍server.checkNewMail()方法,不需要自己启动线程。Timer本身也是多线程同步的,多个线程可以共用一个Timer,不需要外部的同步代码。
      

  6.   

    如果你在页面接收到一个参数 值为中文 那么要考虑到乱码问题 如果第一次乱码的话那么在后面几次的传值中必为乱码 js传值有限制大概不能超过2k (好像是)所以当乱码的大小超过这个限度就会出错 以前做项目遇到过 解决办法尽量不用js传值或不传中文 (不知道我说的这个问题能否解决你的问题)