这几天为了做项目而写了一个比较菜的标签,与大家分享,由于本人比较菜,还希望大家多多提宝贵意见!
涉及到分页的一共有3个类:BasePageTag .java,PageTag ,java,StringUtil .java
BasePageTag .java
- package com.cnc.proud.tag;
-
- import javax.servlet.jsp.tagext.BodyTagSupport;
-
-
-
-
-
- public class BasePageTag extends BodyTagSupport {
-
- private static final long serialVersionUID = 5514331269166734936L;
-
- protected String totalSize;
-
- protected String avgSize;
-
- protected String curPage;
-
- protected String url;
-
- protected String params;
-
- private String tagName;
-
- private String sign;
-
- public BasePageTag() {
- super();
- }
-
- public String getAvgSize() {
- return avgSize;
- }
-
- public void setAvgSize(String avgSize) {
- this.avgSize = avgSize;
- }
-
- public String getCurPage() {
- return curPage;
- }
-
- public void setCurPage(String curPage) {
- this.curPage = curPage;
- }
-
- public String getParams() {
- return params;
- }
-
- public void setParams(String params) {
- this.params = params;
- }
-
- public String getSign() {
- return sign;
- }
-
- public void setSign(String sign) {
- this.sign = sign;
- }
-
- public String getTagName() {
- return tagName;
- }
-
- public void setTagName(String tagName) {
- this.tagName = tagName;
- }
-
- public String getTotalSize() {
- return totalSize;
- }
-
- public void setTotalSize(String totalSize) {
- this.totalSize = totalSize;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public void release() {
- super.release();
- this.totalSize = null;
- this.avgSize = null;
- this.curPage = null;
- this.url = null;
- this.params = null;
- this.tagName = null;
- this.sign = null;
- }
- }
-
PageTag.java
- package com.cnc.proud.util;
-
-
-
-
-
-
- public class StringUtil {
-
- public static boolean isNull(Object obj) {
- boolean conditon = false;
- String result = (String) obj;
- if (result == null || result == "" || result.length() < 1) {
- conditon = true;
- }
- return conditon;
- }
-
- }
-
<!----><tlibversion></tlibversion><jspversion></jspversion><shortname></shortname><description></description><tag></tag><name></name><tagclass></tagclass> <bodycontent> </bodycontent> <attribute></attribute><name></name><required></required><rtexprvalue></rtexprvalue><attribute></attribute><name></name><required></required><rtexprvalue></rtexprvalue><attribute></attribute><name></name><required></required><rtexprvalue></rtexprvalue><attribute></attribute><required></required>
<rtexprvalue></rtexprvalue>PageTag.java是组装字符串,用于显示4个标签(首页,上一页,下一页,尾页)BasePageTag.java定义一些标签属性
StringUtil.java用于判断字符串
proud.tld是定义标签(在附件中)
使用方法:
1,先在web.xml中添加标签描述
2,然后在action中得到各个参数然后将这些参数放到request中
request.setAttribute("curPage", String.valueOf(curPage ));
request.setAttribute("totalSize", String.valueOf(totalSize));
request.setAttribute("avgSize", String.valueOf(avgSize));
request.setAttribute("totalPage", String.valueOf(totalPage));
request.setAttribute("url", url);
request.setAttribute("params", params);
3,jsp页面中加入<!----> ,然后就可以调用标签,这些标签属性都是从request范围内取值,最终生成的html代码
希望大家多提宝贵意见,也希望对初学者能提供帮助!
谢谢!
StringUtil .java