- superallen
- 等级: 初级会员

- 文章: 27
- 积分: 91
- 来自: ...

|
现在说中间的控制层。
在Struts的FORM中,增加private int pageDisplay = 10; 属性,并增加对应的setter和getter方法。这个属性是用来设置每页显示的记录数,10是默认值,可以根据实际情况进行设置。
在Struts的ACTION层,增加一个方法,代码如下
java 代码
- package com.excellence.struts.action;
-
-
- import java.util.List;
-
-
- 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 com.excellence.page.Service;
-
- import com.excellence.struts.form.CheckForm;
-
- public class CheckAction extends Action {
-
- public ActionForward execute(
-
- ActionMapping mapping,
-
- ActionForm form,
-
- HttpServletRequest request,
-
- HttpServletResponse response) {
-
-
-
- setSubPage(request,form);
-
-
-
- return mapping.findForward("result");
-
- }
-
-
-
- private void setSubPage(HttpServletRequest request,ActionForm form){
-
- CheckForm thisForm = (CheckForm)form;
-
- String content = thisForm.getContent();
-
- Service service = new Service();
-
-
-
-
-
- int pageSize = thisForm.getPageDisplay();
-
- request.setAttribute("pageSize",pageSize+"");
-
-
-
- int pageNumber = 1;
-
- String strPageNumber = request.getParameter("page");
-
- if(strPageNumber != null)
-
- pageNumber = Integer.parseInt(strPageNumber);
-
-
-
- int start = 0;
-
- start = (pageNumber - 1)*pageSize;
-
-
-
- List result = service.findByCondition("from Subpage where content like ? order by content",new Object[]{content},start,pageSize);
-
- List counts = service.findByCondition("select count(*) from Subpage where content like ?",new Object[]{content});
-
- int count = Integer.parseInt(counts.get(0).toString());
-
- request.setAttribute("count",count+"");
-
-
-
-
-
- int totalPage = count % pageSize == 0 ? count / pageSize : (count / pageSize + 1);
-
- request.setAttribute("totalPage",totalPage+"");
-
-
-
- request.setAttribute("result",result);
-
- if(result.size() == 0)
-
- request.setAttribute("result",null);
-
- }
-
- }
-
-
主要就是增加了一个私有的方法private void setSubPage(HttpServletRequest request,ActionForm form)。
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- wubaodan
- 等级: 初级会员

- 性别:
 - 文章: 9
- 积分: 40
- 来自: 武汉

|
你的JSP放上来看看
|
返回顶楼 |
|
|
- superallen
- 等级: 初级会员

- 文章: 27
- 积分: 91
- 来自: ...

|
JSP的内容已经写出来了
|
返回顶楼 |
|
|