现在的位置: 首页 > 综合 > 正文

改造一个ajax树型菜单

2013年09月03日 ⁄ 综合 ⁄ 共 2118字 ⁄ 字号 评论关闭

这个例子来自《征服ajax——web2.0开发技术详解》第14章,网上有下载

1      先关闭Statement对象,再关闭ResutlSet对象

      try {//最后关闭ResutltSet,Statement.并释放连接
    if (rs != null)
     rs.close();    //ResultSet对象已关闭
    if (rs.getStatement() != null)    //无法调用其方法,抛错
     rs.getStatement().close();   
    DbManager.releaseConnection();
   } catch (SQLException e) {
    e.printStackTrace();
   }

java.sql.SQLException: Operation not allowed on closed ResultSet. Statements can be retained over result set closure by setting the connection property "retainStatementAfterResultSetClose" to "true".

不允许对已关闭的ResultSet进行操作。只有设置连接属性retainStatementAfterResultSetClose的值为"true",才可在结果集关闭的情况下保留Statements。

2  xmlHttp 

if(window.createRequest)
  {
    try{
      _xmlHttpRequestObj=window.createRequest();
      _xmlHttpRequestObj.open('POST',submitUrl,true);
      _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
      _xmlHttpRequestObj.send();
    }
    catch(ee){}
  }
  else if(window.XMLHttpRequest)
  {
    _xmlHttpRequestObj=new XMLHttpRequest();
    _xmlHttpRequestObj.overrideMimeType('text/xml');
    _xmlHttpRequestObj.open('POST',submitUrl,true);
    _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
    _xmlHttpRequestObj.send("");
  }

  else if(window.ActiveXObject)
  {
    _xmlHttpRequestObj=new ActiveXObject("Microsoft.XMLHTTP");
    _xmlHttpRequestObj.open('POST',submitUrl,true);
    _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
    _xmlHttpRequestObj.send();
  }
};

在ie里会出错,无法获取子菜单。将青色部分和蓝色部分换位,可行。

function parseSubTree(id)
{
  var el= document.getElementById( id );
  var ulElmt= document.createElement("UL");
  ulElmt.innerHTML=_xmlHttpRequestObj.responseText;
  el.appendChild(ulElmt);
  var images = el.getElementsByTagName("IMG");
  images[0].setAttribute("src", "images/minus.gif");
  images[0].setAttribute("onclick", "showHide('"+id+"')");

 // images[0].setAttribute("onclick", new Function("showHide('"+id+"')"));
  var aTag = el.getElementsByTagName("A");
  aTag[0].setAttribute("onclick", "showHide('"+id+"')");

//  aTag[0].setAttribute("onclick", new Function("showHide('"+id+"')"));

  var loadDiv= document.getElementById( "load" );
  loadDiv.style.display="none";
}

在火狐里正常,在ie里菜单展开后,不能收缩;如果用蓝色部分取代青色部分,则在ie里正常,在火狐里菜单展开后,不能收缩。

抱歉!评论已关闭.