首先我们要们通过帖子列表的点击,转发页面到帖子显示的页面,这个过程中request会得到一个id参数,这个参数就是帖子在数据库中的唯一标志. like this
[url]http://127.0.0.1:8888/axbbs/GetPostInfo?id=1[/url] 嗯,这样的方式,告诉GetPostInfo这个servlet我们需要拿到关于帖子标号为1的数据.
好,下面先设计GetPostInfo的PO类
package com.axbbs.po;

public class    RePostPo{
    
   //id
   private int id;
   //引用帖子id
   private int refid;
   //回帖人
   private String postReUserName;
   //回帖内容
   private String postReContent;
   //回帖时间
   private String postReTime;
   //回帖引用图片
   private String postReImgPath;
   //回帖包子
   private String postReFace;
   //是否匿名
   private int postReIsHide;
   //举旗
   private int postReFlag;
    
   /**
    * @return postReFlag
    */

   public int getPostReFlag() {
     return postReFlag;
  }
   /**
    * @param postReFlag 要设置的 postReFlag
    */

   public void setPostReFlag( int postReFlag) {
     this.postReFlag = postReFlag;
  }
   /**
    * @return id
    */

   public int getId() {
     return id;
  }
   /**
    * @param id 要设置的 id
    */

   public void setId( int id) {
     this.id = id;
  }
   /**
    * @return postReContent
    */

   public String getPostReContent() {
     return postReContent;
  }
   /**
    * @param postReContent 要设置的 postReContent
    */

   public void setPostReContent(String postReContent) {
     this.postReContent = postReContent;
  }
   /**
    * @return postReFace
    */

   public String getPostReFace() {
     return postReFace;
  }
   /**
    * @param postReFace 要设置的 postReFace
    */

   public void setPostReFace(String postReFace) {
     this.postReFace = postReFace;
  }
   /**
    * @return postReImgPath
    */

   public String getPostReImgPath() {
     return postReImgPath;
  }
   /**
    * @param postReImgPath 要设置的 postReImgPath
    */

   public void setPostReImgPath(String postReImgPath) {
     this.postReImgPath = postReImgPath;
  }
   /**
    * @return postReIsHide
    */

   public int isPostReIsHide() {
     return postReIsHide;
  }
   /**
    * @param i 要设置的 postReIsHide
    */

   public void setPostReIsHide( int i) {
     this.postReIsHide = i;
  }
   /**
    * @return postReTime
    */

   public String getPostReTime() {
     return postReTime;
  }
   /**
    * @param postReTime 要设置的 postReTime
    */

   public void setPostReTime(String postReTime) {
     this.postReTime = postReTime;
  }
   /**
    * @return postReUserName
    */

   public String getPostReUserName() {
     return postReUserName;
  }
   /**
    * @param postReUserName 要设置的 postReUserName
    */

   public void setPostReUserName(String postReUserName) {
     this.postReUserName = postReUserName;
  }
   /**
    * @return refid
    */

   public int getRefid() {
     return refid;
  }
   /**
    * @param refid 要设置的 refid
    */

   public void setRefid( int refid) {
     this.refid = refid;
  }
    
}
 
OK,在以上这个类的设计中,将帖子的所有属性都包含了进去,下面开始设计GetPostInfo的DAO类
 
package com.axbbs.Dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.axbbs.common.DbUtil;
import com.axbbs.po.RePostPo;

public class GetRePosDAO {
   private DbUtil dbUtil = new DbUtil();

   //
   private Connection conn = dbUtil.getConnection();
    
   public static void main(String[] args){ 
    
/*在主方法测试有没有拿到数据 ,这段代码注释掉了,在测试的时候可以打开
   ArrayList l=new GetRePost().getPost("1");
    for(int i=0;i<l.size();i++){
      System.out.println(((RePostPo) l.get(i)).getId());
      System.out.println(((RePostPo) l.get(i)).getRefid());
      System.out.println(((RePostPo) l.get(i)).getPostReUserName());
      System.out.println(((RePostPo) l.get(i)).getPostReTime());
      System.out.println(((RePostPo) l.get(i)).getPostReContent());
      System.out.println(((RePostPo) l.get(i)).getPostReFace());
      System.out.println(((RePostPo) l.get(i)).getPostReFlag());
      System.out.println(((RePostPo) l.get(i)).getPostReImgPath());
      System.out.println(((RePostPo) l.get(i)).isPostReIsHide());
    }*/

  }
   //回帖信息
   public ArrayList getPost(String id) {
    ArrayList viewList = new ArrayList();
    Statement stmt = null;
    ResultSet rs = null
    String sql = "select * from retopic where refid='"+id+ "'";
    String sql1= "update mainpost set Post_Hits=Post_Hits+1 where id='"+id+ "'";
     try {
      stmt = conn.createStatement();
      rs = stmt.executeQuery(sql);
       while (rs.next()) {
        RePostPo pp = new RePostPo();
        pp.setId(rs.getInt( "id"));
        pp.setRefid(rs.getInt( "refid"));
        pp.setPostReContent(rs.getString( "postcontent"));
        pp.setPostReUserName(rs.getString( "postusername"));
        pp.setPostReTime(rs.getString( "posttime"));
        pp.setPostReFace(rs.getString( "face"));
        pp.setPostReImgPath(rs.getString( "p_w_picpathpath"));
        pp.setPostReFlag(rs.getInt( "flag"));
        pp.setPostReIsHide(rs.getInt( "ishide"));
        viewList.add(pp);        
      }
      stmt.executeUpdate(sql1);
    } catch (SQLException e) {
       // TODO Auto-generated catch block
      e.printStackTrace();
    }

     return viewList;
    
  }
}