service类

// 这是一个查询方法,page是要查询的页码
public Object queryProducts(Integer page) {
	ArrayList<Products> alist = new ArrayList<Products>();
	Object object[] = new Object[3];
	// 参数是要显示的页码和总数据条数
	fenyeService.fenYe(page, this.AllCount()); // AllCount()方法返回总条数(自己写)
	Query query = session.createQuery("from Products");
	// 设置查询从多少条到多少条
	query.setFirstResult(fenyeService.getFirst());// (当前页面-1)X每页条数
	query.setMaxResults(fenyeService.getMax()); // 每页的条数
	alist = (ArrayList) query.list();

	// 将当前页页码和总页数都放进数组,还有alist(查询结果),数组下表从0开始
	object[0] = fenyeService.getCurr_page();
	object[1] = fenyeService.getPages();
	object[2] = alist;

	return object;
}

action

// 查询物品
public String check() throws Exception {
	ArrayList<Products> alist = new ArrayList<Products>();
	Object object[] = new Object[3];
	Map map = ActionContext.getContext().getSession();
	// 查询方法,接收返回的数组
	object = (Object[]) productpervices.queryProducts(page);
	// 前两个存的是当前是第几页和总共的页数,第三个才是产品的集合,判断是否有值
	if (object[2] != null) {
		map.put("object", object);
	}

	return "checkProduct";
}

jsp

<table border="1" bordercolor="green" width="30%" align="center" cellspacing="0">
	<s:if test="#session.object[2]!=null">
		<tr>
			<th>产品ID</th>
			<th>产品名称</th>
			<th>创建者</th>
		</tr>
		<s:iterator value="#session.object[2]" id="pro">
			<tr align="center">
				<td>${pro.pid}</td>
				<td>${pro.pname}</td>
				<td>${pro.member.mname}</td>
			</tr>
		</s:iterator>
	</s:if>
</table>
<br>
<s:a href="http://xxx.blog.163.com/blog/checkproductAction?page=1">【首页】</s:a>
<a rel="nofollow" href="http://xxx.blog.163.com/blog/checkproductAction?page=${sessionScope.object[0]-1}">上一页</a>
<a rel="nofollow" href="http://xxx.blog.163.com/blog/checkproductAction?page=${sessionScope.object[0]+1}">下一页</a>
<a rel="nofollow" href="http://xxx.blog.163.com/blog/checkproductAction?page=${sessionScope.object[1]}">【尾页】</a>
<font color="red">${sessionScope.object[0]}</font>/${sessionScope.object[1]}

这里特别要强调的是:如果超链接里面要使用EL表达式的话,一定不要用struts2标签,否则会出错,

只要使用普通的html标签就好了~

OK,好了,我们现在可以看看效果了,第一次做,有什么不合理的地方,欢迎高手指教!