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">&lt;!--google_ad_client = &quot;pub-1832179689702023&quot;;google_ad_width = 336;google_ad_height = 280;google_ad_format = &quot;336x280_as&quot;;google_ad_type = &quot;text_image&quot;;//2007-01-10: 336_280google_ad_channel = &quot;7111701428&quot;;google_color_border = &quot;FFFFFF&quot;;google_color_bg = &quot;FFFFFF&quot;;google_color_link = &quot;0000FF&quot;;google_color_text = &quot;000000&quot;;google_color_url = &quot;3D81EE&quot;;//--&gt;</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><script>google_protectAndRun(&quot;ads_core.google_render_ad&quot;, google_handleError, google_render_ad);</script>
页:
[1]