• 注册
  • 关于作者
    企业认证:趣记站长
    关注 6 粉丝 4 喜欢 9 内容 992
    江西省·南昌市
    聊天 送礼
    • 查看作者
    • Jsp分页实例代码

      //Author tar(bigangell@yesky.com)

      //您可以任意拷贝复制该代码,但请加上以上作者信息

      //有任何问题请与我联系

      //效果请看 http://210.77.144.64/kk/java/java/article.jsp

      <%@ page import="java.sql.*" %>

      <%@ page import="java.io.*" %>

      <%@ page import="java.util.*" %>

      <jsp:useBean id="sqlconn" scope="page" class="kk.database.sqlconn" />

      <%! String aTitle,aAuthor,AType,ArticleType,InsertTime,Color; %>

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

      <HTML>

      <HEAD>

      <TITLE>ArticleList</TITLE>

      <META NAME="Generator" CONTENT="jBuilder3.5 && jEdit1.0">

      <META NAME="Author" CONTENT="bigangell">

      <META NAME="Keywords" CONTENT="Java,Servlet,Jsp,Beans,PHP">

      <META NAME="Description" CONTENT="A Pure World For Programming Include C/C++,Java">

      <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=gb2312">

      <link rel="stylesheet" href="style.css">

      </head>

      <body bgcolor="#FFFFFF">

      <table width="760" border="0" cellspacing="0" cellpadding="0" align="center">

      <tr>

      <td>

      <table width="750" border="0" cellspacing="2" cellpadding="2" align="center">

      <tr align="center">

      <td>&nbsp;</td>

      </tr>

      <tr>

      <td>

      <table width="740" border="0" cellspacing="1" cellpadding="1" align="center">

      <tr align="center" bgcolor="#CCCCCC">

      <td><b>标题</b></td>

      <td><b>作者</b></td>

      <td><b>类型</b></td>

      <td><b>点击</b></td>

      <td><b>加入时间</b></td>

      </tr>

      <%

      int i;

      int ipage=10; //分页单位

      int allpage; //总页数

      int pages; //接受的页码变量

      int cpage=1; //当前页

      int spage; //开始页

      //数据库连接声明

      java.lang.String sql,pagesql;

      java.sql.ResultSet rs,pagers;

      pagesql = "select count(a_id) as A from article";

      //取总文章数

      pagers = sqlconn.executeQuery(pagesql);

      int allCol = pagers.getInt("A");

      //获得总页面数

      allpage = (int)Math.ceil((allCol + ipage-1) / ipage);

      //判断参数pages是否为空

      if (request.getParameter("pages")==null) {

      pages=1;

      } else {

      pages = new Integer(request.getParameter("pages")).intValue();

      }

      //判断当前页

      if(pages > allpage // pages == 0){

      cpage = 1;

      } else {

      cpage = pages;

      }

      //判断起始页

      spage=(cpage-1)*ipage;

      sql = "select a_id,a_title,a_author,aID,a_time,a_readtime,sID from article order by a_id desc limit "+ spage +","+ ipage;

      rs = sqlconn.executeQuery(sql);

      int cu=1;

      //循环取数据库值

      while (rs.next()) {

      int aID = rs.getInt("a_id");

      aTitle = rs.getString("a_title");

      aAuthor = rs.getString("a_author");

      int ArticleTypeID = rs.getInt("aID");

      int ReadTime = rs.getInt("a_readtime");

      InsertTime = rs.getString("a_time");

      if (cu % 2 == 0) { Color="#DBECFD"; }

      else { Color="#C6E1FD"; }

      switch (ArticleTypeID) {

      case(1):

      ArticleType="小说";

      break;

      case(2):

      ArticleType="散文";

      break;

      case(3):

      ArticleType="诗歌";

      break;

      case(4):

      ArticleType="随笔";

      break;

      }

      %>

      <tr bgcolor="<%= Color %>">

      <td width="300"><a href="viewarticle.jsp?aID=<%= aID %>"><%= aTitle %></a></td>

      <td align="center" width="100"><%= aAuthor %></td>

      <td align="center" width="50"><%= ArticleType %>//Author tar(bigangell@yesky.com)

      //您可以任意拷贝复制该代码,但请加上以上作者信息

      //有任何问题请与我联系

      //效果请看 http://210.77.144.64/kk/java/java/article.jsp

      <%@ page import="java.sql.*" %>

      <%@ page import="java.io.*" %>

      <%@ page import="java.util.*" %>

      <jsp:useBean id="sqlconn" scope="page" class="kk.database.sqlconn" />

      <%! String aTitle,aAuthor,AType,ArticleType,InsertTime,Color; %>

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

      <HTML>

      <HEAD>

      <TITLE>ArticleList</TITLE>

      <META NAME="Generator" CONTENT="jBuilder3.5 && jEdit1.0">

      <META NAME="Author" CONTENT="bigangell">

      <META NAME="Keywords" CONTENT="Java,Servlet,Jsp,Beans,PHP">

      <META NAME="Description" CONTENT="A Pure World For Programming Include C/C++,Java">

      <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=gb2312">

      <link rel="stylesheet" href="style.css">

      </head>

      <body bgcolor="#FFFFFF">

      <table width="760" border="0" cellspacing="0" cellpadding="0" align="center">

      <tr>

      <td>

      <table width="750" border="0" cellspacing="2" cellpadding="2" align="center">

      <tr align="center">

      <td>&nbsp;</td>

      </tr>

      <tr>

      <td>

      <table width="740" border="0" cellspacing="1" cellpadding="1" align="center">

      <tr align="center" bgcolor="#CCCCCC">

      <td><b>标题</b></td>

      <td><b>作者</b></td>

      <td><b>类型</b></td>

      <td><b>点击</b></td>

      <td><b>加入时间</b></td>

      </tr>

      <%

      int i;

      int ipage=10; //分页单位

      int allpage; //总页数

      int pages; //接受的页码变量

      int cpage=1; //当前页

      int spage; //开始页

      //数据库连接声明

      java.lang.String sql,pagesql;

      java.sql.ResultSet rs,pagers;

      pagesql = "select count(a_id) as A from article";

      //取总文章数

      pagers = sqlconn.executeQuery(pagesql);

      int allCol = pagers.getInt("A");

      //获得总页面数

      allpage = (int)Math.ceil((allCol + ipage-1) / ipage);

      //判断参数pages是否为空

      if (request.getParameter("pages")==null) {

      pages=1;

      } else {

      pages = new Integer(request.getParameter("pages")).intValue();

      }

      //判断当前页

      if(pages > allpage // pages == 0){

      cpage = 1;

      } else {

      cpage = pages;

      }

      //判断起始页

      spage=(cpage-1)*ipage;

      sql = "select a_id,a_title,a_author,aID,a_time,a_readtime,sID from article order by a_id desc limit "+ spage +","+ ipage;

      rs = sqlconn.executeQuery(sql);

      int cu=1;

      //循环取数据库值

      while (rs.next()) {

      int aID = rs.getInt("a_id");

      aTitle = rs.getString("a_title");

      aAuthor = rs.getString("a_author");

      int ArticleTypeID = rs.getInt("aID");

      int ReadTime = rs.getInt("a_readtime");

      InsertTime = rs.getString("a_time");

      if (cu % 2 == 0) { Color="#DBECFD"; }

      else { Color="#C6E1FD"; }

      switch (ArticleTypeID) {

      case(1):

      ArticleType="小说";

      break;

      case(2):

      ArticleType="散文";

      break;

      case(3):

      ArticleType="诗歌";

      break;

      case(4):

      ArticleType="随笔";

      break;

      }

      %>

      <tr bgcolor="<%= Color %>">

      <td width="300"><a href="viewarticle.jsp?aID=<%= aID %>"><%= aTitle %></a></td>

      <td align="center" width="100"><%= aAuthor %></td>

      <td align="center" width="50"><%= ArticleType %></td>

      <td align="center" width="50"><%= ReadTime %></td>

      <td align="center" width="240"><%= InsertTime %></td>

      </tr>

      <%

      cu++;

      }

      %>

      <tr bgcolor="#CCCCCC">

      <td colspan="5" align="right" valign="middle">共 <%= allCol %>条记录 共 <%= allpage %>页 <% if (cpage>1) { %><a href="article.jsp?pages=<%= cpage-1 %>"><img src="images/prev.gif" border="0"></a><% } if (cpage<allpage) { %><a href="article.jsp?pages=<%= cpage+1 %>"><img src="images/next.gif" border="0"></a><% } %> / <% for (i=1;i<=allpage;i++) { if (i != pages) {%><a href="article.jsp?pages=<%= i %>"><%= i %></a>&nbsp;<% } }%></td>

      </tr>

      </table>

      </td>

      </tr>

      </table>

      </td>

      </tr>

      </table>

      </body>

      </html> 

      JSP应用的安全问题
      基于JSP实现数据库中图片的存储与显示,利用DWR开发基于Ajax的文件上载portlet,解决JSP开发Web程序中文显示三种方法,JSP结合XML+XSLT将输出转换HTML,JSP连接SQL Server 2000系统配置,Java和JSP编程应该注意的六个常见问题,JSP上传图片并生成缩略图,JSP上传图片并生成缩略图,用JSP从数据库中读取图片并显示在网页上,JSP中SQL数据库编程技术,jsp读取大对象CLOB并生成xml文件示例,JSP中读文件和写文件的例子,OpenCms文件导入过程初探,巧用文件保存对象来提高JSP的性能,JSP中日期的用法,JSP数据库连接方式总结,JSP的9种基本内置组件,编写线程安全的JSP程序,其他常见JSP开发环境,关于Java Servlet的Filter 技术
      JSP

    • 0
    • 0
    • 0
    • 56
    • 单栏布局 侧栏位置: