huibin 发表于 2013-2-6 10:08:36

struts2实现分页显示

 在开发web程序时,从数据库中取出来的数据一般都要分页显示在页面上,分页显示的方法非常多,有人写自定义标签,用自己写的标签进行分页显示,我个人觉得这是一种比较好的方法。下面是我用Struts2做的一个分页显示实例,基本的思路是:把数据库表中的每一行数据封装成一个对象,用一个返回类型为List的方法返回这些对象,接着在Struts2的action里面定义一个List属性,用这个List来接收从数据库中查询出来并进行了封装的那些对象,然后通过Struts2的标签遍历List里的每个对象,并把这些对象里所包含的属性取出来展现在页面上。下面是具体的步骤:
所用工具:JDK1.6 + MyEclipse6.0 + Tomcat6.0 + MySQL5.0 + struts 2.0.11
1、新建一个web工程,导入struts2中相应的jar包和mysql数据驱动包。
2、编写web.xml文件,其代码如下:
<script type="text/javascript"><!--google_ad_client = "pub-1832179689702023";google_ad_width = 336;google_ad_height = 280;google_ad_format = "336x280_as";google_ad_type = "text_image";//2007-01-10: 336_280google_ad_channel = "7111701428";google_color_border = "FFFFFF";google_color_bg = "FFFFFF";google_color_link = "0000FF";google_color_text = "000000";google_color_url = "3D81EE";//--></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><script>google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);</script>
页: [1]
查看完整版本: struts2实现分页显示