//查找记录
public List getAllGuestBooks(int firstResult){
Session session = this.getSession();
return session.createQuery("from GuestBook order by id desc").setFirstResult(0).setMaxResults(10).list(); }
-->>>
//查找记录
public List getAllGuestBooks(int firstResult){
return this.bookDAO.getAllGuestBooks(firstResult);
}
action:
private GuestBookBiz biz = new GuestBookBiz();
public GuestBookBiz getBiz() {
return biz;
}
public void setBiz(GuestBookBiz biz) {
this.biz = biz;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm showForm = (DynaActionForm) form;// TODO Auto-generated method stub
System.out.println("11111111111111111111"); System.out.println("2222222222222222");
List list = this.biz.getAllGuestBooks(0);//刷新七八次以上控制台就不输出3333333...了,why?
System.out.println("33333333333333333333");
request.setAttribute("list", list);

return mapping.findForward("list");
}
    <table border="3">
     <logic:iterate id="guestBook" name="list" length="10" offset="${pageNum*10}">
     <tr>
     <td>${guestBook.id }     </td>
     <td>${guestBook.name }   </td>
     <td>${guestBook.email }  </td>
     <td>${guestBook.url }    </td>
     <td>${guestBook.title }  </td>
     <td>${guestBook.context }</td>
     <td>${guestBook.time }   </td>
     </tr>
     </logic:iterate>
    </table>
页面数据可以显示,但页面刷新七八次以上就没反应了,很奇怪!有人知道怎么回事吗?

解决方案 »

  1.   

    action中:
     List list = this.biz.getAllGuestBooks(0);//这里没有0,写错了,已经在fristResult设置了
      

  2.   

    没异常么还有你的session是怎么管理的,用了spring吗
      

  3.   

    试试这个,死马当活马医吧: public List getAllGuestBooks(int firstResult){
            Session session = this.getSession();
            session.clear(); 
            return session.createQuery("from GuestBook order by id desc").setFirstResult(0).setMaxResults(10).list();    }
      

  4.   

    是不是延迟加载的问题。
    试试lazy="false"
      

  5.   

    这个要看看你是否使用了Spring的了
    http://blog.csdn.net/AWUSOFT/archive/2008/12/28/3626279.aspx
      

  6.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      
      <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
      </context-param>
      <listener>
    看看什么有问题
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      
      
      <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>3</param-value>
        </init-param>
        <init-param>
          <param-name>detail</param-name>
          <param-value>3</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      
      
      <welcome-file-list>
        <welcome-file>/form/show.jsp</welcome-file>
      </welcome-file-list>
    </web-app><?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="DataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
    </property>
    <property name="url"
    value="jdbc:sqlserver://localhost:1433;databaseName=guestBook">
    </property>
    <property name="username" value="sa"></property>
    </bean>
    <bean id="SessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="DataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SQLServerDialect
    </prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/entity/GuestBook.hbm.xml</value></list>
    </property></bean>
    <bean id="GuestBookDAO" class="com.entity.GuestBookDAO">
    <property name="sessionFactory">
    <ref bean="SessionFactory" />
    </property>
    </bean>
    <bean id="GuestBookBiz" class="com.biz.GuestBookBiz">
    <property name="bookDAO">
    <ref bean="GuestBookDAO"/>
    </property>
    </bean>
    <bean name="/show" class="com.web.struts.action.ShowAction">
    <property name="biz" ref="GuestBookBiz"></property>
    </bean> </beans><?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.entity.GuestBook" table="guestBook" schema="dbo" catalog="guestBook">
            <id name="id" type="java.lang.Integer">
                <column name="id" />
                <generator class="native" />
            </id>
            <property name="name" type="java.lang.String">
                <column name="name" length="50" not-null="true" />
            </property>
            <property name="email" type="java.lang.String">
                <column name="email" length="50" not-null="true" />
            </property>
            <property name="url" type="java.lang.String">
                <column name="url" length="50" not-null="true" />
            </property>
            <property name="title" type="java.lang.String">
                <column name="title" length="50" not-null="true" />
            </property>
            <property name="context" type="java.lang.String">
                <column name="context" length="200" not-null="true" />
            </property>
            <property name="time" type="java.lang.String">
                <column name="time" length="50" not-null="true" />
            </property>
        </class>
    </hibernate-mapping>
      

  7.   

    #12楼:
    按照你提供的思路我这样写:
    //查找记录
    public List getAllGuestBooks(){
    return (List)getHibernateTemplate().execute(new HibernateCallback()
    {
    public Object doInHibernate(Session session) throws HibernateException 
    {

    Query query = session.createQuery("from GuestBook order by id desc"); 
    query.setFirstResult(0);
    query.setMaxResults(10);
    return query.list();
    } },true);
    }
    还是不行
      

  8.   

    Session session = this.getSession();
            return session.createQuery("from GuestBook order by id desc").setFirstResult(0).setMaxResults(10).list();这个不用关闭的?session.close()
      

  9.   

    //查找记录
    public List getAllGuestBooks(){
    Session session = this.getSession();
    session.close();//这里关闭是错误的!session.clear();也没用
    return session.createQuery("from GuestBook").setFirstResult(0).setMaxResults(10).list(); }
      

  10.   

    Session session = this.getSession();
            session.close();//这里关闭是错误的!session.clear();也没用
            return session.createQuery("from GuestBook").setFirstResult(0).setMaxResults(10).list()
    相当无语
    Session session = this.getSession();
    list ls=session.createQuery("from GuestBook").setFirstResult(0).setMaxResults(10).list()
    sesseion.close();
    return ls;
      

  11.   

    楼主你好,我前两天跟你一样,仔细检查了一下。我的session没有close()
      

  12.   

    Session session = this.getSession();
    Query query = session.createQuery("from GuestBook order by id desc");
    List list = query.list();
    session.clear();
    return list;//这样也没用!我仔细到网上找了一下,原来是applicationContext.xml配置少了一个设置数据库最大连接数<!-- 数据库的最大连接数 --> 
    <property name="maxActive" value="200"> </property>
    只要加上这一句就把问题解决了!汗啊~~!!
    #17楼 ,我也蛮喜欢这个女的!应该是演皇太子的初恋的那个女的!
      

  13.   

    查处结束后关闭session就好了session.colse()
      

  14.   

    只是关闭session.close() 好象也没用!刷新七八次的时候依然没反应
    只要在applicationContext.xml加上这句<!-- 数据库的最大连接数 --> 
    <property name="maxActive" value="200"> </property>就解决了!
    好象只要有设置数据库最大连接数,
    session.close()没有同样也可以查询,没有任何影响!
    应该是spring管理自动关闭的吧!就象我们不需要考虑数据库连接关闭一样的道理吧!
      

  15.   

    哎,这么明显的问题:典型的拉屎不擦屁股帖!!!List resultList = null;
    Session session = getSession();
    try {
        String queryString = "from Table T where ...";
        Query query = session.createQuery(queryString);
        query.setFirstResult(...).setMaxResults(...);
        resultList = query.list();
    }catch(Exception e) {
        e.printStackTrace();
    }finally {
        session.close();
    }
    return resultList;
      

  16.   

    治标不治本,如果刷新的次数多了,一样没反应,你现在不过是把最大连接数该大点了,所以才没看出来。如上边各位所说,你的session没有关闭是主要原因。要么就关闭session,要么就如12楼的思路那样。
      

  17.   

    如果只是 关闭 session 还是刷新七八次以上没反应
    session.close()
    再加上<property name="maxActive" value="200"> </property> 就搞定了!<property name="maxActive" value="200"> </property> 这句不能少!
      

  18.   

    你可以写个sql语句测试以下,具体是什么我也忘记了
      

  19.   


    ssh整合,Spring,Struts,Hibernate持久层,不需要关闭Session session=this.getSession(); 
            Query query= session.createQuery("from GuestBook order by id desc"); 
            List list= query.list(); 
            session.close();
    return list;如果不加<property name="maxActive" value="200">还是会没反应
    到底是什么原因呢?
      

  20.   

    其实,你如果用回调的方法,那你就不用去关的,由spring来帮你关,如果你把它单独获取出来,那你就要自己去关闭它。
    this.getHibernateTemplate().executeFind(new HibernateCallback(){ public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
    // TODO Auto-generated method stub
    return null;
    }

    });
      

  21.   

    唉,还是要把代码发出来....:
    WEB.xml中配置<filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    <init-param>
                <param-name>singleSession</param-name>
                <param-value>true</param-value>
            </init-param>
      </filter>public boolean deleteObject(final Object o) {
    getHibernateTemplate().execute(new HibernateCallback()//这里使用了匿名内部类 
    {
    public Object doInHibernate(Session session)//Spring进行事务维护 省去每次创建session和关闭session
    throws HibernateException
    {
    if(o!=null)
    {
    session.delete(o);
    session.flush();
    }
    return null;
    }
    }, true);
    return true;
    }
    不需要去管开启和关闭