查询action如下:输出了xml文档:
PrintWriter out = ServletActionContext.getResponse().getWriter();
String CONTENT_TYPE = "text/xml; charset=GBK";
ServletActionContext.getResponse().setContentType(CONTENT_TYPE);
ServletActionContext.getResponse().addHeader("Expires", "0");// 清除缓存
ServletActionContext.getResponse().addHeader("Cache-Control","no-store,must-revalidate");
ServletActionContext.getResponse().addHeader("Cache-Control","post-check=0,pre-check=0");
ServletActionContext.getResponse().addHeader("Pragma", "no-cache");
out.println("<?xml version=\"1.0\" encoding=\"GBK\"?>");//生成XML文档
out.println("<Powertype>");
for (int i = 0; i < li.size(); i++) {
out.println("<xmllist>");
Powertype mes = (Powertype) li.get(i);
//System.out.println(mes.getId());
out.println("<powertypeid>" + mes.getId()+ "</powertypeid>");
out.println("<powertypename>" + mes.getVPowerTypeName()+ "</powertypename>");
out.println("<powertypeorderid>" + mes.getIPowerOrderId()+ "</powertypeorderid>");
out.println("<powertypecontent> </powertypecontent>");
out.println("<powertypere>" + mes.getVPowerTypeRe()+ "</powertypere>");
out.println("<powertypestate>" + mes.getIState()+ "</powertypestate>");
//out.println("<cont>"+ new String(nulltoString(mes.getCont()).getBytes("GBK"),"ISO-8859-1") + "</cont>");
out.println("</xmllist>");
}
out.println("<Pageinfo>");
// 总页数
out.println("<maxPage>" + bean.getPageCount()+ "</maxPage>");
// 待显示页码
out.println("<curPage>" + bean.getPage() + "</curPage>");
// 记录总数
out.println("<maxRowCount>" + bean.getRowcount()+ "</maxRowCount>");
// 每页显示的记录数
out.println("<pageMaxRows>" + bean.getPageSize()+ "</pageMaxRows>");
out.println("</Pageinfo>");
out.println("</Powertype>"); out.close();
return null;
=============================================================================================
JSP页面用jquery ajax测试调用 <script type="text/javascript"> //定义AJAX变量
  var xmlHttp = false;
  var  pageMaxRows; //当前页行数
  var  curPage; //当前页数
  var  maxPage; //最大页数
  var  maxRowCount; //最大行数
  var list;//显示页数的tbody  function getValue(urlXML)//读取数据
  { 
  $.ajax({
type:"GET",
url:urlXML,
dataType:"xml",
success:function(myXML){
$(myXML).find("Powertype").each(
function(){
sName="",sState="",sOrderid="";
sName=$(this).find("powertypename").text();
sState=$(this).find(powertypestate).text();
sOrderid=$(this).find(powertypeorderid).text(); $("#Powertype).append($("<tr><td>"+sName+"</td><td>"+sState+"</td><td>"+sOrderid+"</td></tr>"));
}
);
}
});
  }
</script>
<table id="Powertype"></table>
数据是显示出来了,但是多点几次下一页上一页,或刷新,系统就停滞了,崩溃一样,总是要重启tomcat才行,不知道这是不是关于什么绶存的问题呢?

解决方案 »

  1.   

    连数据库了么?如果连了,检查看看是否关闭connection了
      

  2.   

    肯定是连接接了吧,不然就不显示查询到的数据了吧,具体是怎么样我也是新手,
    spring管理的!查询dao
    PowertypeDAOCustom {
    private static final Log log = LogFactory.getLog(PowertypeDAO.class);
    public PowertypeDAOCustomImpl() {}
    public List getPowertype(PageBean pagebean) {
    String sql = "from Powertype";
    org.hibernate.Query query = this.getSession().createQuery(sql);
    // 利用Query和过滤器Filter实现集合分页
    try {
    query.setFirstResult((pagebean.getPage()-1)*pagebean.getPageSize());// 读取记录的开始位置
    query.setMaxResults(pagebean.getPageSize());// 设置每页显示的记录数
    return query.list();
    } catch (Exception ex) {// 有些数据库可能不支持这种分页方式
    ex.printStackTrace(); }
    return getPowertype();// 返回不支持分页的数据
    }
      

  3.   

    org.hibernate.Query query = this.getSession().createQuery(sql); 
    这里this.getSession()获取的session没有关闭导致的。
      

  4.   

    在 URL 参数后加上 "?timestamp=" + new Date().getTime();
      

  5.   

    请问在哪里写上关闭!关于session真的是比较陌生,是不是要在这里加上一句
    session.close(我是asp转过来的,呵呵,暂这么写)
    return getPowertype();// 返回不支持分页的数据 
      

  6.   

    肯定是连接接了吧,不然就不显示查询到的数据了吧,具体是怎么样我也是新手, 
    spring管理的!查询dao 
    PowertypeDAOCustom { 
    private static final Log log = LogFactory.getLog(PowertypeDAO.class); 
    public PowertypeDAOCustomImpl() {} 
    public List getPowertype(PageBean pagebean) { 
    String sql = "from Powertype"; 
    Session session = this.getSession();
    org.hibernate.Query query = session.createQuery(sql); 

    // 利用Query和过滤器Filter实现集合分页 
    try { 
    query.setFirstResult((pagebean.getPage()-1)*pagebean.getPageSize());// 读取记录的开始位置 
    query.setMaxResults(pagebean.getPageSize());// 设置每页显示的记录数 
    return query.list(); 
    } catch (Exception ex) {// 有些数据库可能不支持这种分页方式 
    ex.printStackTrace(); } finally{
       session.close();
    }
    return getPowertype();// 返回不支持分页的数据 
    }
      

  7.   

    你好:wangpeng88888888,还是出现崩溃,到崩溃为止后台输出了如下信息:2010-01-19 02:52:36,224 DEBUG [org.springframework.orm.hibernate3.SessionFactoryUtils] - Opening Hibernate Session
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 12638695562
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.engine.query.QueryPlanCache] - located HQL query plan in cache (from Powertype)
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.engine.query.QueryPlanCache] - located HQL query plan in cache (from Powertype)
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.engine.query.HQLQueryPlan] - find: from Powertype
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.engine.QueryParameters] - named parameters: {}
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 1)
    2010-01-19 02:52:36,225 DEBUG [org.hibernate.jdbc.ConnectionManager] - opening JDBC connection
      

  8.   

    看不出来什么错误,你把application.xml中最大连接数设置大一点吧。
      

  9.   

    噢,据说session是有spring自动关闭的,完了查询事务要放在service业务层,是这样吗
      

  10.   

    好的,不过把连接数据改大点应该是下策.问题虽然没解决,但起码知道问题出现在哪!应该就是session没有自动关闭的问题,我再找找,给分
      

  11.   


            return (getHibernateTemplate().execute(new HibernateCallback()
            {
                public Object doInHibernate(Session session) throws HibernateException 
                {
                    
                    Query query = session.createQuery("你的SQL"); 
                    query.setFirstResult(param);
                    query.setMaxResults(param);
                    return query.list();
                }        });这种写法是由spring去关闭自动关闭的。你那种写法需要自己去关闭。事务一般都在service层去控制