package com.yeshi.fanli.tag;
|
|
import java.io.IOException;
|
import java.util.Iterator;
|
import java.util.Map;
|
|
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspWriter;
|
import javax.servlet.jsp.tagext.TagSupport;
|
|
public class PageTag extends TagSupport {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
private String url; // ���ӵ�ַ
|
private int pageindex;// ��ǰҳ
|
private int pagesize; // ҳ��С
|
private int totalLines; // �ܼ�¼����
|
private Map<String, String> params;// ���Ӳ���
|
private String preimage;
|
private String nextimage;
|
private String pagebg;
|
private String inputbg;
|
private String gobg;
|
|
public int getPageindex() {
|
return pageindex;
|
}
|
|
public void setPageindex(int pageindex) {
|
this.pageindex = pageindex;
|
}
|
|
public String getPreimage() {
|
return preimage;
|
}
|
|
public void setPreimage(String preimage) {
|
this.preimage = preimage;
|
}
|
|
public String getNextimage() {
|
return nextimage;
|
}
|
|
public void setNextimage(String nextimage) {
|
this.nextimage = nextimage;
|
}
|
|
public String getPagebg() {
|
return pagebg;
|
}
|
|
public void setPagebg(String pagebg) {
|
this.pagebg = pagebg;
|
}
|
|
public String getInputbg() {
|
return inputbg;
|
}
|
|
public void setInputbg(String inputbg) {
|
this.inputbg = inputbg;
|
}
|
|
public String getGobg() {
|
return gobg;
|
}
|
|
public void setGobg(String gobg) {
|
this.gobg = gobg;
|
}
|
|
public String getUrl() {
|
return url;
|
}
|
|
public void setUrl(String url) {
|
this.url = url;
|
}
|
|
public int getPagesize() {
|
return pagesize;
|
}
|
|
public void setPagesize(int pagesize) {
|
this.pagesize = pagesize;
|
}
|
|
public int getTotalLines() {
|
return totalLines;
|
}
|
|
public void setTotalLines(int totalLines) {
|
this.totalLines = totalLines;
|
}
|
|
public Map<String, String> getParams() {
|
return params;
|
}
|
|
public void setParams(Map<String, String> params) {
|
this.params = params;
|
}
|
|
private int totalPages() {
|
return totalLines % pagesize == 0 ? totalLines / pagesize : totalLines
|
/ pagesize + 1;
|
}
|
|
// ��ȡ�����URL
|
private String getAllUrl(int pageIndex) {
|
String baseUrl = url;
|
baseUrl += "?pageIndex=" + pageIndex;
|
if (params != null) {
|
Iterator<String> its = params.keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = params.get(key);
|
baseUrl += "&" + key + "=" + value;
|
}
|
}
|
return baseUrl;
|
}
|
|
@Override
|
public int doStartTag() throws JspException {
|
int totalPage = totalPages();
|
String style = "background:url("
|
+ pagebg
|
+ ");width:38px;height:38px;text-align:center;line-height:38px;float:left;margin-left:1px;border:0;";
|
|
String shenYuStyle = "float:left;margin-left:10px;height:38px;line-height:38px;";
|
|
String jumpText = "float:left;margin-left:107px;height:38px;line-height:38px;";
|
|
String inputStyle = "border:0;background:url("
|
+ pagebg
|
+ ");width:36px;height:36px;text-align:center;line-height:38px;float:left;margin-left:10px;";
|
String content = "<div style='" + style + "'>"
|
+ "<a href=''><img src='" + preimage + "' /></a></div>"
|
+ "<div ><a href=''><input type='button' value='1' style='"
|
+ style + "' /></a></div>" + "<div style='" + style
|
+ "'><a href=''><img src='" + nextimage + "'/></a></div>"
|
+ "<div style='" + jumpText + "'>��ǰҳ:" + pageindex + "/"
|
+ totalPage + " ��ת����</div>"
|
+ "<div ><input type='text' style='" + inputStyle
|
+ "' /></div>" + "<a href=''><div style='" + style
|
+ "'>Go</div></a>";
|
if (pageindex < 1)
|
pageindex = 1;
|
if (pageindex > totalPage)
|
pageindex = totalPage;
|
String c = "<div style='" + style + "'>" + "<a href='"
|
+ getAllUrl((pageindex > 1 ? pageindex - 1 : 1))
|
+ "'><img src='" + preimage + "' /></a></div>";
|
if (totalPage < 6) {
|
|
for (int i = 0; i < totalPage; i++) {
|
c += "<div><a href='" + getAllUrl((i + 1))
|
+ "'><input type='button' value='" + (i + 1)
|
+ "' style='" + style + "' /></a></div>";
|
}
|
|
} else {
|
if (Math.abs(pageindex) < 3 || Math.abs(pageindex - totalPage) < 3) {
|
if (Math.abs(pageindex) <= 3) {
|
for (int i = 0; i < 5; i++) {
|
c += "<div><a href='" + getAllUrl((i + 1))
|
+ "'><input type='button' value='" + (i + 1)
|
+ "' style='" + style + "' /></a></div>";
|
}
|
} else {
|
|
for (int i = 0; i < 5; i++) {
|
c += "<div><a href='" + getAllUrl(totalPage - 4 + i)
|
+ "'><input type='button' value='"
|
+ (totalPage - 4 + i) + "' style='" + style
|
+ "' /></a></div>";
|
}
|
|
}
|
|
} else {
|
|
for (int i = 0; i < 5; i++) {
|
c += "<div><a href='" + getAllUrl(i + pageindex - 2)
|
+ "'><input type='button' value='"
|
+ (i + pageindex - 2) + "' style='" + style
|
+ "' /></a></div>";
|
}
|
}
|
}
|
|
c += "<div style='"
|
+ style
|
+ "'><a href='"
|
+ getAllUrl(pageindex + 1 > totalPage ? totalPage
|
: pageindex + 1) + "'><img src='" + nextimage
|
+ "'/></a></div>" + "<div style='" + jumpText + "'>��ǰҳ:"
|
+ pageindex + "/" + totalPage + " ��ת����</div>"
|
+ "<div ><input type='text' id='jumppage' style='" + inputStyle
|
+ "' /></div>"
|
+ "<a href='#' onclick='javascript:getPage()'><div style='"
|
+ style + "'>Go</div>";
|
|
System.out.println(pageindex + "-" + totalLines + "-" + pagesize + "-"
|
+ url + "-" + preimage + "-" + nextimage + "-" + pagebg + "-"
|
+ inputbg + "-" + gobg + "-"
|
+ pageContext.getRequest().getLocalAddr());
|
|
JspWriter out = this.pageContext.getOut();
|
try {
|
out.print("<script type='text/javascript'>alert('123123'); function getPage(){alert('page');window.location="
|
+ url
|
+ "?pageIndex=document.getElementById('jumppage').value; }</script>");
|
out.print(c);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
|
return EVAL_BODY_INCLUDE;
|
}
|
|
@Override
|
public int doEndTag() throws JspException {
|
// TODO Auto-generated method stub
|
return super.doEndTag();
|
}
|
|
}
|