import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.GenericValidator;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport
{
/**
* 注释内容
*/
private static final long serialVersionUID = -8648961157882604306L;
private ArrayList<UserInfo> userList;
private int count;
public String execute()
throws Exception
{
HttpServletRequest request = ServletActionContext.getRequest();
String pageIndexName =
new org.displaytag.util.ParamEncoder("element").encodeParameterName(org.displaytag.tags.TableTagParameters.PARAMETER_PAGE); // 页数的参数名
int pageSize = 10; //每页显示的条数
int pageIndex =
GenericValidator.isBlankOrNull(request.getParameter(pageIndexName)) ? 0
: (Integer.parseInt(request.getParameter(pageIndexName)) - 1); //当前页数
count = 50;
userList = getList(pageIndex, pageSize);
return SUCCESS;
}
/**
* <一句话功能简述>
* <功能详细描述>
* @param begin
* @param pageSize
* @return
* @see [类、类#方法、类#成员]
*/
public ArrayList<UserInfo> getList(int begin, int pageSize)
{
ArrayList<UserInfo> list = new ArrayList<UserInfo>();
UserInfo userInfo = null;
begin = begin * pageSize;
pageSize = (begin + 1) * pageSize;
for (int i = begin; i <= pageSize; i++)
{
userInfo = new UserInfo();
userInfo.setId("id" + i);
userInfo.setName("name" + i);
userInfo.setPass("pass" + i);
userInfo.setHref("href" + i);
list.add(userInfo);
}
return list;
}
public int getCount()
{
return count;
}
public void setCount(int count)
{
this.count = count;
}
public ArrayList<UserInfo> getUserList()
{
return userList;
}
public void setUserList(ArrayList<UserInfo> userList)
{
this.userList = userList;
}
}
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/screen.css" />
<link rel="stylesheet" type="text/css" href="css/maven-theme.css" />
<link rel="stylesheet" type="text/css" href="css/css.css" />
</head>
<body>
<div align="center">
<display:table name="userList" cellspacing="0" cellpadding="0" pagesize="10" class="simple" htmlId="tabId" id="element"
requestURI="displayTag.action" partialList="true" size="count">
<display:column property="id" title="用户ID" />
<display:column property="name" title="用户名"/>
<display:column property="pass" title="用户密码" />
<display:column property="href" title="连接"/>
</display:table>
</div>
</body>
</html>