日期:2014-05-16 浏览次数:20327 次
<body> <% // 编码转换 request.setCharacterEncoding("GB2312") ; if(session.getAttribute("uname")!=null) { // 用户已登陆 %> <p align="center" >留言板V1.0</p> <p align="center" >留言管理列表</p><form method="POST" action="shownote.jsp"> <table width="816" height="137" border="1" align="center"> <tr> <td width="86">留言编号</td> <td width="111">作者</td> <td width="180">标题</td> <td width="291">内容</td> <td width="99">操作</td> </tr> <%//变量声明 int intPageSize =10; //一页显示的记录数 int intRowCount; //记录总数 int intPageCount=0; //总页数 int intPage; //待显示页码 java.lang.String strPage; //取得待显示页码 strPage = request.getParameter("page"); if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 intPage = 1; } else{//将字符串转换成整型 intPage = java.lang.Integer.parseInt(strPage); if(intPage<1) intPage = 1; } %> <%! Connection conn = ConnectDataBase.getConnection(); Statement statement = null; String sql = null; ResultSet rs = null; %> <% try { statement = (Statement) conn.createStatement(); sql = "select * from note"; rs = statement.executeQuery(sql); rs.last();//??光标在最后一行 intRowCount = rs.getRow();//获得当前行号 //记算总页数 intPageCount = (intRowCount+intPageSize-1) / intPageSize; //调整待显示的页码 if(intPage>intPageCount) intPage = intPageCount; if(intPageCount>0){ //将记录指针定位到待显示页的第一条记录上 rs.absolute((intPage-1) * intPageSize + 1); }//显示数据 int i = 0; while (i<intPageSize && rs.next()) { String name = rs.getString(1); String tittle = rs.getString(2); String content = rs.getString(3); int num = rs.getInt(4); %> <tr> <td><%=num %></td> <td><%=name %></td> <td><%=tittle %></td> <td><%=content %></td> <td><a href="delete.jsp?id=<%=num %>" onclick="javascript:return p_del()" >删除</a></td> </tr> <% i++; } rs.close(); statement.close(); conn.close(); }catch(Exception e){ } %> </table> <form method="POST" action="shownote.jsp"> 第<%=intPage%>页 共<%=intPageCount%>页 <%if(intPage<intPageCount){%><a href="shownote.jsp?page=<%=intPage+1%>">下一页 </a><%}%> <%if(intPage>1){%><a href="shownote.jsp?page=<%=intPage-1%>"> 上一页</a><%}%> 转到第:<input type="text" name="page" size="8"> 页 <span><input class=buttonface type="submit" value="GO" name="cndok"></span> </form> <p align="center"><strong><