SSH 페이지 나누기 코드

4623 단어
import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class DoFenYeTaglib extends SimpleTagSupport {
 private int pageNum;//    
 private int totalPage;//   
 private int allCounts;//       
 private int count;//       
 
 private String className;
 private String para;
 private String functionName;
 
 public int getCount() {
  return count;
 }

 public void setCount(int count) {
  this.count = count;
 }

 public String getFunctionName() {
  return functionName;
 }

 public int getAllCounts() {
  return allCounts;
 }

 public void setAllCounts(int allCounts) {
  this.allCounts = allCounts;
 }

 public void setFunctionName(String functionName) {
  this.functionName = functionName;
 }

 public String getPara() {
  return para;
 }

 public void setPara(String para) {
  this.para = para;
 }

 public int getPageNum() {
  return pageNum;
 }

 public void setPageNum(int pageNum) {
  this.pageNum = pageNum;
 }

 public int getTotalPage() {
  return totalPage;
 }

 public void setTotalPage(int totalPage) {
  this.totalPage = totalPage;
 }

 public String getClassName() {
  return className;
 }

 public void setClassName(String className) {
  this.className = className;
 }

 public void doTag() throws JspException, IOException {
  JspWriter out = getJspContext().getOut();
  
        int liststep = 10;//        
        int pages = 1;//       
        if (pageNum != 0) {
            pages = pageNum;//      
        }
       
        if (totalPage < pages) {
            pages = totalPage;//          ,            
        }
        if (pages < 1) {
            pages = 1;//        1,        1
        }
        int listbegin = (pages - (int) Math.ceil((double) liststep / 2));//            
        if (listbegin < 1) {
            listbegin = 1;
        }
        int listend = pages + liststep/2;//          
        if (listend > totalPage) {
            listend = totalPage + 1;
        }
          
        //          
        if (pages > 1) {
         out.print("<a href='" + this.className + ".do?" + this.para + "="+ this.functionName + "&pageNum=1&count=" 
           + this.count + "&allCounts=" + this.allCounts +"'>      </a>");
         out.print("<a href='" + this.className + ".do?" + this.para + "="+ this.functionName + "&pageNum=" + (this.pageNum - 1)
     + "&count=" + this.count + "&allCounts=" + this.allCounts + "'>   <      </a>");
        }
        //      
        for (int i = listbegin; i < listend; i++) {
            if (i != pages) {//  i      
             out.print("<a href='" + this.className + ".do?" + this.para + "="+ this.functionName + "&pageNum=" + i
         + "&count=" + this.count + "&allCounts=" + this.allCounts + "'> <b>" + i + "</b> </a>");
            } else {
             out.print(" <b>" + i + " </b>");
            }
        }
        //         
        if (pages != totalPage) {
         out.print("<a href='" + this.className + ".do?" + this.para + "="+ this.functionName + "&pageNum=" + (this.pageNum + 1)
     + "&count=" + this.count + "&allCounts=" + this.allCounts + "'>      >   </a>");
         out.print("<a href='" + this.className + ".do?" + this.para + "="+ this.functionName + "&pageNum=" + this.totalPage
     + "&count=" + this.count + "&allCounts=" + this.allCounts + "'>      </a>");
        }
  super.doTag();
 }
}


좋은 웹페이지 즐겨찾기