使用javascript+OGNL做分页

本文介绍了一个使用Struts2框架实现的学生信息分页查询功能。通过Action类处理分页逻辑,并利用JSP页面展示学生信息列表及提供翻页功能。该示例涵盖了从数据库查询数据到前端展示的完整流程。

Action类:

import java.util.Map;

import com.opensymphony.xwork2.ActionSupport; import com.service.IStudentServices;

public class QueryStudentAction extends ActionSupport {  private Integer pageSize = 3; //声明固定的行数  private Integer pageIndex = 1; //页码  private IStudentServices iss;  //调用service层对象  private Map map=new HashMap(); //一个容器  @Override  public String execute() throws Exception {   map.put("list", iss.queryList(pageSize, pageIndex));   map.put("count", iss.getCount(pageSize));   return SUCCESS;  }

 public Integer getPageSize() {   return pageSize;  }

 public void setPageSize(Integer pageSize) {   this.pageSize = pageSize;  }

 public Integer getPageIndex() {   return pageIndex;  }

 public void setPageIndex(Integer pageIndex) {   this.pageIndex = pageIndex;  }

 public IStudentServices getIss() {   return iss;  }

 public void setIss(IStudentServices iss) {   this.iss = iss;  }

 public Map getMap() {   return map;  }

 public void setMap(Map map) {   this.map = map;  }

}

--------------------------------------------------------------------------------------------------------------------

jsp显示层:

<body>
  <s:debug></s:debug>
   <form action="" method="post" name="myfrom">
     <table>
      <tr>
       <td>ID</td>
       <td>姓名</td>
      </tr>
      <!-- 使用OGNL迭代标签获取map里的值 -->
      <s:iterator value="map.list" var="item">
       ?<tr>
        <td><s:property value="#item.id" /></td>
        <td><s:property value="#item.name" /></td>
       </tr>
      </s:iterator>
      <!-- 将总页码数和当前页码放到隐藏域,注意页码必须和action里的一致为了替换掉之前的页码 -->
      <input type ="hidden" id="count" value="<s:property value='map.count' />" />
      <input type ="hidden" name="pageIndex" id="index" value="<s:property value='pageIndex' />" />
      
     </table>
     <input type="button" value="首页" onclick="fnFirst()" />
     <input type="button"  value="上一页" onclick="fnBack()" />
     <input type="button"  value="下一页" onclick="fnNext()" />
     <input type="button" value="尾页" onclick="fnlast()" />
     
     <SCRIPT type="text/javascript">
       //获取隐藏域的总页数
       var count=document.getElementById("count").value;
       //获取当前的页码
       var index=document.getElementById("index").value;
       
      //上页操作 
      function fnBack(){
       index--;
       document.getElementById("index").value=index;
       if(index<1){
        document.getElementById("index").value=1;
       }
       
       alert(document.getElementById("index").value);
       document.myfrom.action="query";
       document.myfrom.submit();
      }
      
      //下页操作
      function fnNext(){
       index++;
       document.getElementById("index").value=index;
       if(index>count){
        document.getElementById("index").value=count;
       }
       
       alert(document.getElementById("index").value);
       document.myfrom.action="query";
       document.myfrom.submit();
      }
      //首页操作
      function fnFirst(){
       document.getElementById("index").value=1;
      }
      //尾页操作
      function fnlast(){
       document.getElementById("index").value=count;
      }
     </SCRIPT>
    </form>
  </body>

 

 

 

转载于:https://www.cnblogs.com/cifeng/archive/2013/04/14/3020235.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值