admin
2021-04-02 d551bef5e2b09bd98681cf97807988c9863e66fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package com.yeshi.buwan.web.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();
    }
 
}