/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package struts.action;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import page.bean.DatabaseConn;
import page.bean.PageResultSet;
import page.bean.ContactBO;
import struts.form.LoginForm;
/**
* MyEclipse Struts
* Creation date: 04-02-2008
*
* XDoclet definition:
* @struts.action path="/login" input="/login.jsp" scope="request" validate="true"
* @struts.action-forward path="/index.jsp"
*/
public class LoginAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
ContactBO userBO=new ContactBO();
//先从业务处理逻辑类中取出数据(ArrayList或Vector格式)
Collection data;
try {
data = userBO.findContact(DatabaseConn.getConnection());
//再得到当前页curPage和每页记录数pageSize
//int curPage = Integer.parseInt((String)request.getParameter("cur_page"));
int curPage = 1;
String cur = request.getParameter("cur_page");
System.out.println("--------------: "+cur);
if(cur!=null && cur !=""){
curPage = new Integer(cur).intValue();
}
int pageSize=10;
//然后生成PageResultSet对象
PageResultSet dataList = new PageResultSet(data, curPage, pageSize);
request.setAttribute("usersList", dataList);
return mapping.findForward("sss");
} catch (Exception e) {
e.printStackTrace();
return mapping.getInputForward();
}
}
}
3.以下是显示分页的页面
复制代码 代码如下:
<%@ page language="java" import="java.util.*,page.bean.Contact,page.bean.PageResultSet"
pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "https://www.jb51.net/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="https://www.jb51.net/<%=basePath%>">
<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 type="text/css" href="https://www.jb51.net/styles.css">
-->
</head>
<body>
<table>
<%
PageResultSet pageResultSet = (PageResultSet) request.getAttribute("usersList");
ArrayList usersList = (ArrayList) pageResultSet.getData();
for (int i = 0; i < usersList.size(); i++) {
Contact co = (Contact) usersList.get(i);
%>
<tr>
<td>
<%=co.getId() %>
</td>
<td>
<a href="https://www.jb51.net/login.do?id=<%=co.getId()%>"><%=co.getUsername()%></a>
</td>
<td>
<%=co.getMobile() %>
</td>
<td>
<%=co.getMail() %>
</td>
<td>
<%=co.getPhone() %>
</td>
<td>
<%=co.getMem() %>
</td>
<td>
<%=co.getLastcontact() %>
</td>
</tr>
<%
}
%>
</table>
<!-- 显示分页工具栏 -->
<%=pageResultSet.getToolBar("login.do")%>
</body>
</html>
您可能感兴趣的文章: