做的是类似BBS.点击完回复该帖后,帖子插如数据库了,但是没有在该页面显示出来.好像没有从新请求服务器。不知道那里不对
流程是这样的.
1.这是发表帖子的页面错.提交到ReplyAction插入到数据库,插入没问题就不贴ReplyAction了 。</head>
  <%
      User user=(User)session.getAttribute("user");
   %>
  <%!int i=0; %>
  <body>
    <div align="left">
        发表于:<bean:write name="message" property="pubDate"/><br>
        <textarea rows="10" cols="50"><bean:write name="message" property="context"/></textarea>楼主<br>
        <logic:iterate id="reply" name="reply">
        发表于:<bean:write name="reply" property="pubDate"/><br>
              <textarea><bean:write name="reply" property="context"/></textarea><%=++i%>楼<br>
        </logic:iterate>
        <html:form action="reply">
        <html:hidden property="pubName" value="<%=user.getUserName()%>"/>
        <html:textarea  property="context" value=""></html:textarea><br>
        <html:submit>回复该贴</html:submit>
        </html:form>
    </div>
  </body>
</html:html>
2.插入完然后由ReplyAction mapping到ContextAction进行显示,下边是ContextActionpublic ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String id=request.getParameter("id");//获取主帖ID
HttpSession session =request.getSession();
Message message=null;
if(id!=null)
{
session.setAttribute("id", id);
MessageDAO dao=new MessageDAO();
message=dao.findById(Integer.valueOf(id));
}
else{
id=(String)session.getAttribute("id");//如果ID为空从session中得到
MessageDAO dao=new MessageDAO();
message=dao.findById(Integer.valueOf(id));//获取主贴
}
Set set=message.getRReplies();//获取回帖列表
session.setAttribute("message", message);
request.setAttribute("reply", set);
return mapping.findForward("contextlist");//从新mapping到发帖子的页面

}

解决方案 »

  1.   

    用sql查查看,是不是外键关联不对。
      

  2.   

    插入数据库的值,重新在set到bean里
      

  3.   

    你去查一下message=dao.findById这个方法
    如果你是用hibernate来做查询,并且设置了message这个映射类关联RReplies是lazy=true的话
    那么你就要在findById这个方法中,注意是这个方法中,不是在方法执行后,要在方法中如下调用一下:public Message findById(int id) {
      Message message = ……; // 你的查询方法
      message.getRReplies().size(); // 注意,一定要调用这句
      return message;
    }
      

  4.   

    帖子已经插入数据库了那就是排序问题了,存在就肯定能找出来
    要不就是hibernate缓存了查询结果,清理一下缓存 hibernate我不熟悉,但你可以试一下
      

  5.   

    我用的Habernate3默认的lazy
    不知道你调用那句什么用途,我试了下没起作用。
      

  6.   

    果然是缓存的问题,我clear()了一下果然好了,下来就是排序的问题了