搜索类
public class Search
{    private Collection coll;
    private Connection conn;
    private int articleTotal;    public Search()
    {
    
        conn = null;
        articleTotal = 0;
        try
        {conn = DBConn.getConnection();
            System.out.println("33333");
        }
        catch(Exception exception) { }
    }    public Collection getColl()
    {
        return coll;
    }    public int getArticleTotal()
    {
        return articleTotal;
    }    public void doSearchUserName(String s)
    {
     try{
    Collection collection=null;
Statement stmt=conn.createStatement();
String s1="select userName from userinfo where userName='" + s + "'";
ResultSet rst;
for(rst=stmt.executeQuery(s1);rst.next();){

UserForm user1=new UserForm();
user1.setUserName(rst.getString(1));
collection.add(user1);
coll.add(user1);
articleTotal++;
System.out.println("4");

            rst.close();
    
        }
        catch(Exception exception1) {
         }
        }
    }搜索Action
public class SearchAction extends Action
{
ArrayList allItems=new ArrayList();
public void SetAllItem(ArrayList allItems){
this.allItems=allItems;
}
public ArrayList getAllItem(){
return allItems;
}
 
    public SearchAction()
    {
    }
       public ActionForward execute(ActionMapping actionmapping, ActionForm actionform, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
    {
        DynaActionForm dynaactionform = (DynaActionForm)actionform;
        String s = (String)dynaactionform.get("userName");
        if(s == null || s.equals(""))
        {
            httpservletrequest.setAttribute("message", "Please input keyword!");
            return actionmapping.findForward("showMessage");
        } else
        {
            Search search = new Search();
            search.doSearchUserName(s);
            httpservletrequest.setAttribute("coll", search.getColl());
            System.out.println("111");
            
            return actionmapping.findForward("showSearchResult");
        }
    }
}
页面控制
public class PageController {
    
    private int pageNumber;
    private int lastIndexOfPage;
    private int itemsPerPage=20;
    private int itemsInPage;
    private int lastPageNumber;
    private boolean hasPrevious;
    private boolean hasNext;
    private Collection allItems;
    /**
     * @return Returns the allItems.
     */
    public Collection getAllItems() {
            return allItems;
    }
    /**
     * @param allItems The allItems to set.
     */
    public void setAllItems(Collection allItems) {
            this.allItems = allItems;
    }
    /**
     * @return Returns the hasNext.
     */
    public boolean isHasNext() {
            return hasNext;
    }
    /**
     * @param hasNext The hasNext to set.
     */
    public void setHasNext() {
            int items=pageNumber*itemsPerPage;
            if(items>=allItems.size()){
                    this.hasNext =false;
            }else{
                    this.hasNext=true;
            }
    }
    /**
     * @return Returns the hasPrevious.
     */
    public boolean isHasPrevious() {
            return hasPrevious;
    }
    /**
     * @param hasPrevious The hasPrevious to set.
     */
    public void setHasPrevious() {
            if(pageNumber==1){
                    this.hasPrevious=false;
            }else{
                    this.hasPrevious=true;
            }
    }
    /**
     * @return Returns the itemsInPage.
     */
    public int getItemsInPage() {
            return this.itemsInPage;
    }
    /**
     * @param itemsInPage The itemsInPage to set.
     */
    public void setItemsInPage() {
            int temp=pageNumber*itemsPerPage;
            if(temp<=allItems.size()){
                    this.itemsInPage=itemsPerPage;
            }else{
                    this.itemsInPage=( allItems.size() - ((pageNumber-1)*itemsPerPage ));
            }
    }
    /**
     * @return Returns the itemsPerPage.
     */
    public int getItemsPerPage() {
            return itemsPerPage;
    }
    /**
     * @param itemsPerPage The itemsPerPage to set.
     */
    public void setItemsPerPage(int itemsPerPage) {
            this.itemsPerPage = itemsPerPage;
    }
    /**
     * @return Returns the pageNumber.
     */
    public int getPageNumber() {
            return pageNumber;
    }
    /**
     * @param pageNumber The pageNumber to set.
     */
    public void setPageNumber(int pageNumber) {
            this.pageNumber = pageNumber;
    }
    
    /**
     * @return Returns the lastIndexOfPage.
     */
    public int getLastIndexOfPage() {
            return lastIndexOfPage;
    }
    /**
     * @param lastIndexOfPage The lastIndexOfPage to set.
     */
    public void setLastIndexOfPage() {
            this.lastIndexOfPage =(pageNumber -1)*itemsPerPage;
    }
    
    /**
     * @return Returns the lastPageNumber.
     */
    public int getLastPageNumber() {
            return lastPageNumber;
    }
    /**
     * @param lastPageNumber The lastPageNumber to set.
     */
    public void setLastPageNumber() {
            if(allItems.size()%itemsPerPage==0){
                    this.lastPageNumber =allItems.size()/itemsPerPage;
            }else{
                    this.lastPageNumber =allItems.size()/itemsPerPage+1;
            }
    }
}
PageAction类 public class PageAction extends ForwardAction {
                public ActionForward execute(ActionMapping arg0, ActionForm arg1,
                        HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
                // TODO Auto-generated method stub
                String action=null;
                HttpSession session=arg2.getSession(true);
                action=arg2.getParameter("action").trim();
                PageController controller=(PageController)session.getAttribute("controller");
                int pageNumber=controller.getPageNumber();
                if(action.compareToIgnoreCase("next")==0){
                        ++pageNumber;
                }else if(action.compareToIgnoreCase("pervious")==0){
                        --pageNumber;
                }else if(action.compareToIgnoreCase("first")==0){
                        pageNumber=1;
                }else if(action.compareToIgnoreCase("last")==0){
                        pageNumber=controller.getLastPageNumber();
                }
                controller.setPageNumber(pageNumber);
                controller.setHasNext();
                controller.setHasPrevious();
                controller.setItemsInPage();
                controller.setLastIndexOfPage();
                return super.execute(arg0, arg1, arg2, arg3);
        }
}