本文共 4731 字,大约阅读时间需要 15 分钟。
package png.houtai; import java.util.*; import java.sql.*; import javax.servlet.jsp.tagext.*; import javax.servlet.jsp.JspWriter; import png.db.DB; public class bookTag extends TagSupport { public bookTag() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } private String page="1"; private String type; private String id; public void setPage(String page) { if(page.equals("")||page.trim().length()<1) return; this.page = page; } public void setId(String id){ this.id=id; } public String getId(){ return id; } public void setType(String type) { this.type = type; } public String getPage() { return page; } public String getType() { return type; } public int doStartTag(){ JspWriter out=pageContext.getOut(); int i=0;//环 int sumrow;//总行数 int sumye;//总页数 int yerow;//每页行数 int page;//待显示页码 yerow=4; String strrow="";//接收intpage传来的值 String strSQL; strrow=this.getPage(); page=Integer.parseInt(strrow); if(page<1){ page=1; } try{ strSQL="select * from BookInfo"; Statement st=null; ResultSet set=null; Connection con=null; DB db=new DB(); con=db.conn(); st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); set=st.executeQuery(strSQL); set.last();// 光标在最后一行 sumrow=set.getRow();//每页行数 sumye=(sumrow+yerow-1)/yerow;//总页数 // 调整待显示的页码 if(page>sumye){ page=sumye; } out.print("<form method='get' action='/Root/shan'>"); out.print(" 第" + page + "页"); out.print(" 共" + sumye + "页"); if (page < sumye) { out.print("<a href='/Root/Manager/gaibook.jsp?id="+id+"&page=" + (page + 1) + "'>下一页</a>"); } if (page > 1) { out.print("<a href='/Root/Manager/gaibook.jsp?id="+id+"&page=" + (page - 1) + "'>上一页</a>"); } out.print("<table border='1' width='170' cellspacing='0' cellpadding='0'>"); out.print("<tr><th>选择/不选</th>"); out.print("<th>图书编号</th>"); out.print("<th>图书名称</th>"); out.print("<th>图书类型</th>"); out.print("<th>出版社名称</th>"); out.print("<th>作者名称</th>"); out.print("<th>图书介绍</th>"); out.print("<th>图书价格</th>"); out.print("<th>发行日期</th>"); out.print("<th>上架日期</th>"); out.print("<th>是否新书</th>"); out.print("<th>是否推荐</th>"); out.print("<th>图书数量</th>"); out.print("<th>修改</th>"); //out.print("<th>删除</th>"); out.print("</tr>"); if (sumye > 0) { // 将记录指针定位到待显示页的第一条记录上 set.absolute((page - 1) * yerow + 1); // 显示数据 i = 0; String user_id, user_name; // 遍历记录集,注意判断结束的方法 while (i < yerow && !set.isAfterLast()) { // 获取记录 String BookConver=set.getString(1); String BookId=set.getString(2); String BookName=set.getString(3); String BookType=set.getString(4); String BookPubliSher=set.getString(5); String BookAuthor=set.getString(6); String Bookintorduce=set.getString(7); String BookPrice=set.getString(8); String BookDate =set.getString(9); String BookIntime=set.getString(10); String BookNewBook=set.getString(11); String BookCommend=set.getString(12); String BookSum=set.getString(13); out.print("<tr>"); out.print("<td ><input type='checkbox' name='id' value='"+BookId+"'/></td>"); out.print("<td ><input type='text' name='BookId' id='BookId' value='"+BookId+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='BookName' value='"+BookName+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='BookType' value='"+BookType+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='BookPubliSher' value='"+BookPubliSher+"' readonly='readonly'/></td>"); out.print("<td ><input type='text' name='BookAuthor' value='"+BookAuthor+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='Bookintorduce' value='"+Bookintorduce+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='BookPrice' value='"+BookPrice+"' readonly='readonly'/></td>"); out.print("<td ><input type='text' name='BookDate' value='"+BookDate+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='BookIntime' value='"+BookIntime+"' readonly='readonly' /></td>"); out.print("<td ><input type='text' name='BookNewBook' value='"+BookNewBook+"' readonly='readonly'/></td>"); out.print("<td ><input type='text' name='BookCommend' value='"+BookCommend+"' readonly='readonly'/></td>"); out.print("<td ><input type='text' name='BookSum' value='"+BookSum+"' readonly='readonly'/></td>"); out.print("<td ><a href='gai.jsp?BookId="+BookId+"'>修改</a></td>"); set.next(); i++; } } out.print("<tr><td colspan='15' align='center'><input type='submit' name='gai' value='删除' /></td></tr>"); out.print(" </table>"); out.print(" </form>"); // 关闭结果集 set.close(); // 关闭SQL语句对象 st.close(); // 关闭数据库 con.close(); }catch(Exception e){ System.out.print(e.getMessage()); } return this.SKIP_BODY; } private void jbInit() throws Exception { } }
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2010/12/20/1911869.html,如需转载请自行联系原作者