---------------==========JSB 模式通用分页算法==========---------------
1.建立PageBean
把PageBean放入相应的Bean目录;
2.配置资源文件
URL:com/kevinb/jsb16/property/ApplicationResources.proterties
Content:
DB_USER=sa
DB_PSW=ffffff
DB_SERVER=kevinb
PAGE_SIZE=3
3.配置Dao
/** database user */
private String dbUser;
/** database password */
private String dbPsw;
/** database server */
private String dbServer;
//取得数据库连接参数
public BBSDaoImpl() {
ResourceBundle bundle = ResourceBundle.getBundle("com/kevinb/jsb16/property/ApplicationResources");
this.dbUser = bundle.getString("DB_USER");
this.dbPsw = bundle.getString("DB_PSW");
this.dbServer = bundle.getString("DB_SERVER");
}
public Map<String, Object> getAllBBSContent(int nowPage) {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
List<BbsContentBean> bbsList = new ArrayList<BbsContentBean>();
PageBean pageBean = null;
Map<String, Object> bbsMap = new HashMap<String, Object>();
conn = ConnectMSSQLBase.getMSSQL2005Connect(dbUser, dbPsw, dbServer);
String sql = "select contentId,userId,topic,bbsContent,createTime "
+ "from dbo.bbs_content";
try {
st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery(sql);
//让rs滚动取得总记录数据
rs.last(); //下滚
int allSize = rs.getRow(); //取得总记录数据
rs.beforeFirst(); //rs再次回滚初始位置
pageBean = new PageBean(nowPage,allSize);
//根据当前页滚动无用记录,调整指针位置到第一条记录处
for(int i = 0;i<((nowPage - 1) * pageBean.getPageSize());i++){
rs.next();
}
//开始取得数
for(int i = 0;i<pageBean.getPageSize();i++){
BbsContentBean bbsContentBean = new BbsContentBean();
if(!rs.next()){
break;
}
bbsContentBean.setContentId(rs.getInt("contentId"));
bbsContentBean.setUserId(rs.getInt("userId"));
bbsContentBean.setTopic(rs.getString("topic"));
bbsContentBean.setBbsContent(rs.getString("bbsContent"));
bbsContentBean.setCreateTime(rs.getString("createTime"));
bbsList.add(bbsContentBean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
try {
ConnectMSSQLBase.closeConnect(conn, st, rs);
} catch (SQLException e) {
e.printStackTrace();
}
}
//处理返回值
bbsMap.put("bbsList", bbsList);
bbsMap.put("pageBean", pageBean);
return bbsMap;
}
4.配置Servlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String snowPage = request.getParameter("nowPage");
if(snowPage == null || snowPage.equals("")){
snowPage = "1";
}
int nowPage = Integer.parseInt(snowPage);
Map<String , Object> bbsMap = this.iBBSDao.getAllBBSContent(nowPage);
PageBean pageBean = (PageBean)bbsMap.get("pageBean");
List<BbsContentBean> bbsList = (ArrayList<BbsContentBean>)bbsMap.get("bbsList");
request.setAttribute("pageBean", pageBean);
request.setAttribute("bbsList", bbsList);
request.getRequestDispatcher("bbs/bbsView.jsp").forward(request, response);
}
5.配置JSP
<body>
<h4 style="text-align: center;">BBS content</h4>
<table border="1">
<tr>
<td>contentId</td>
<td>userId</td>
<td>topic</td>
<td>bbsContent</td>
<td>createTime</td>
<td>Process</td>
</tr>
<c:forEach var="bbs" items="${bbsList}">
<tr>
<td>${bbs.contentId }</td>
<td>${bbs.userId }</td>
<td>${bbs.topic }</td>
<td>${bbs.bbsContent }</td>
<td>${bbs.createTime }</td>
<td>Process</td>
</tr>
</c:forEach>
<tr>
<td colspan="6" align="center">
<a href="BBSViewServlet?nowPage=1">首页</a>
<a href="BBSViewServlet?nowPage=${pageBean.prePage }">上一页</a>
<a href="BBSViewServlet?nowPage=${pageBean.nextPage }">下一页</a>
<a href="BBSViewServlet?nowPage=${pageBean.allPage }">尾页</a>
</td>
</tr>
</table>
<br><br>
<a href="index.jsp">Back</a>
</body>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Kevinb_Page.rar (37个子文件)
Kevinb_Page
JSB+Page
PageBean.java 2KB
PageSet.txt 4KB
JSB16(Page_complete)
.project 1KB
.mymetadata 288B
WebRoot
WEB-INF
web.xml 2KB
lib
sqljdbc.jar 570KB
kevinb.jar 25KB
classes
com
kevinb
jsb16
bean
UserBean.class 2KB
PageBean.class 2KB
BbsContentBean.class 1KB
dao
UserDaoImpl.class 2KB
IUserDao.class 181B
BBSDaoImpl.class 3KB
IBBSDao.class 243B
servlet
UserLoginServlet.class 3KB
BBSViewServlet.class 2KB
filter
ProCNFilter.class 1KB
RightFilter.class 2KB
property
ApplicationResources.properties 176B
index.jsp 2KB
META-INF
MANIFEST.MF 39B
bbs
bbsView.jsp 2KB
bbsInsert.jsp 820B
setUp
crebas.sql 2KB
.myeclipse
src
com
kevinb
jsb16
bean
PageBean.java 2KB
UserBean.java 1014B
BbsContentBean.java 857B
dao
IBBSDao.java 235B
BBSDaoImpl.java 3KB
UserDaoImpl.java 2KB
IUserDao.java 211B
servlet
UserLoginServlet.java 3KB
BBSViewServlet.java 2KB
filter
ProCNFilter.java 1KB
RightFilter.java 1KB
property
ApplicationResources.properties 176B
.classpath 501B
共 37 条
- 1
资源评论
- 北京智友乐动科技有限公司2014-07-08看着不太明白
zewenbai
- 粉丝: 3
- 资源: 75
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功