Struts分页
*********************************************************************************************************************
执行过程在这里说明一下
首先 http://localhost:xxxx/xxx/index.jsp
然后单击 显示列表
会执行struts-config.xml 对应的 ation-mappings中action中的 path="/query" type="xxx.QueryAction"
转到对应的QueryAction.java
如果执行成功 QueryAction就会返回 mapping.findWorad("succecc");
再到struts-config.xml ation-mappings中action中的 path="/query" type="xxx.QueryAction"中的
<forward name="success" path="/query.jsp" />
跳转到query.jsp
query.jsp 遍历会话的集合来显示数据 单击链接就会显示不同的内容
由于个人能力有限,如有不足,敬请谅解!!!!
*********************************************************************************************************************
重要用到ArrayList
Struts标签库logic /bean/html
模型PageBean




































































DataBaseOperator 执行数据库操作返回ArrayList集合为PageBean所用












public UserBean(DataSource ds){
try{
conn = ds.getConnection();
}catch(SQLException e){
e.printStackTrace();
}
}
public ArrayList selectemd()...{ String strsql = " xxxxxx";
ArrayList ay = new ArrayList();
int i = 0;
try...{
xxx= conn.xxxxx();
rs = xxx.executeQuery(); //返回记录集
while(rs.next())...{
xxxx qf = new xxx(); //定义一个bean和数据库对应字段
qf.setId(rs.getInt(1));
qf.setName(rs.getString(2));
qf.setAge(rs.getInt(3));
qf.setSex(rs.getString(4));
qf.setDep(rs.getString(5));
qf.setDepname(rs.getString(6));
qf.setWork(rs.getString(7));
qf.setWorkname(rs.getString(8));
ay.add(i,qf); //将bean绑定到集合中
i++;
}
}catch(SQLException e)...{
e.printStackTrace();
}
return ay; //返回集合
}
.......
}



QueryAction.java




























































struts-config.xml



































index.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<html:link page="/query.do">
显示列表
</html:link>
</body>
</html:html>
query.jsp
<%@ page language="java" pageEncoding="gb2312"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>JSP for queryForm form</title>
</head>
<body>
<h1>列表
</h1>
<html:errors />
<table width="700"
border="1" style="background:lavender;border-color:blue" cellpadding="5">
<tr >
<th>xxx</th>
<th>xxx</th>
<th>xxx</th>
</tr>
<!-- iterate over the results of the query -->
<bean:define id="ay" name="pb" property="pageData"></bean:define>
<logic:iterate id="element" name="ay">
<tr bgColor="#eef4f9" align="center">
<td>
<bean:write name="element" property="id" />
</td>
<td>
<bean:write name="element" property="name" />
</td>
<td>
<bean:write name="element" property="age" />
</td>
<td>
</td>
<td>
<bean:write name="element" property="depname" />
</td>
<td>
<bean:write name="element" property="workname" />
</td>
</tr>
</logic:iterate>
<tr>
共<bean:write name="pb" property="maxPage"/>页 第<bean:write name="pb" property="curPage"/>页 共<bean:write name="pb" property="rowNum"/>条信息
<logic:notEqual name="pb" property="curPage" value="1">
<html:link page="/page.do?curPage=${pb.curPage - 1}">上一页</html:link>
</logic:notEqual>
<logic:notEqual name="pb" property="curPage" value="${pb.maxPage}">
<html:link page="/page.do?curPage=${pb.curPage + 1}">下一页</html:link>
</logic:notEqual>
</tr>
</table>
</body>
</html>
*************************************************************************************************************
执行过程在这里说明一下
首先 http://localhost:xxxx/xxx/index.jsp
然后单击 显示列表
会执行struts-config.xml 对应的 ation-mappings中action中的 path="/query" type="xxx.QueryAction"
转到对应的QueryAction.java
如果执行成功 QueryAction就会返回 mapping.findWorad("succecc");
再到struts-config.xml ation-mappings中action中的 path="/query" type="xxx.QueryAction"中的
<forward name="success" path="/query.jsp" />
跳转到query.jsp
query.jsp 遍历会话的集合来显示数据 单击链接就会显示不同的内容
由于个人能力有限,如有不足,敬请谅解!!!!