jumppage.java

来自「这个是一个网站的简单源码」· Java 代码 · 共 80 行

JAVA
80
字号
package com.jewel.tag.pagination;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
/**
 * <p>Title: www.entel.com.cn</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: entel</p>
 * @author chendesheng
 * @version 1.0
 */

public class JumpPage extends TagSupport implements PagerInterface {
  private String offset = "0";
  private String length = "10";
  private String targetPage;

  public int doStartTag() throws JspException {
    Common comm = new Common((HttpServletRequest) pageContext.getRequest());
    this.setLength(""+comm.pageLength);
    String currentPageCount = pageContext.getRequest().getParameter("offset");
    if(currentPageCount == null && comm.offset!=0 )
      currentPageCount = ""+comm.offset;
    // judge the current page
    int group =0;
    int crPage =0;
    if(currentPageCount!=null && !currentPageCount.equalsIgnoreCase("")){
      try{
        crPage = Integer.parseInt(currentPageCount)/comm.pageLength;
        if((crPage+1) % comm.jumpCount  == 0 )
          group = (crPage+1) / comm.jumpCount ;
        else
          group = crPage / comm.jumpCount;
        if(Integer.parseInt(currentPageCount)>comm.AllElementCount){
          group = 0; crPage = 0;
        }
      }catch(Exception e){
        group = 0;
        crPage = 0;
      }
    }
    String out = comm.generateJump(group,crPage) ;
    write(out);
    return SKIP_BODY;
  }


  private void write(String param) throws JspException {
    try {
      pageContext.getOut().write(param);
    } catch (IOException oe) {
      throw new JspTagException("IOException while writing to the Client: " +
                                oe.getMessage());
    }
  }

  public String getTargetPage() {
    return targetPage;
  }
  public void setTargetPage(String targetPage) {
    this.targetPage = targetPage;
  }
  public String getLength() {
    return length;
  }
  public void setLength(String length) {
    this.length = length;
  }
  public void setOffset(String offset) {
    this.offset = offset;
  }
  public String getOffset() {
    return offset;
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?