tld tag page address

2010-04-17  来源:本站原创  分类:Java  人气:296 

my-tag.tld

<?xml  version="1.0"  encoding="utf-8" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>mytag</short-name>
 <uri>/mytag</uri>
 <!--  Inheritance struts2 tags  ComponentTagSupport -->
    <tag>
     <name>page</name>
        <tag-class>com.itmg.tools.mytags.PageTag</tag-class>
  <attribute>
      <name>action</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
      <name>index</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
      <name>maxIndex</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
      <name>size</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
   <name>groupSize</name>
   <required>false</required>
   <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
      <name>styleClass</name>
      <required>false</required>
      <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
      <name>theme</name>
      <required>false</required>
      <rtexprvalue>true</rtexprvalue>
  </attribute>
    </tag>
</taglib>

PageBean.java

package com.itmg.tools.page;

/**
 *  The paging information data model
 *@author Jason
 */
public class PageBean implements java.io.Serializable{
        private static final long serialVersionUID = 1L;

        private int offset;// Off  

        private int length;
        private int begin;
        private int end;
        private int total;
        private int curPage;
        private int totalPage;

    private int startPage;
    private int endPage;

    private int gotoPage;// Which page you want to go to the  

    public PageBean() {
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getBegin() {
        return begin;
    }

    public void setBegin(int begin) {
        this.begin = begin;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getCurPage() {
        return curPage;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

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

        public int getGotoPage() {
                return gotoPage;
        }

        public void setGotoPage(int gotoPage) {
                this.gotoPage = gotoPage;
        }
}

PageHandler.java

package com.itmg.tools.page;

import javax.servlet.http.HttpServletRequest;
import com.itmg.util.Constants;

/**
 *  Paging class, handles the paging logic
 *
 * @author Jason
 */
public class PageHandler {

        /**
         *  Get initialized paging information
         *
         * @param request
         * @return
         */
        public static PageBean initPage(HttpServletRequest request) {
                int length = Constants.PART_PAGE_PER_COUNT;
                int offset = 0;
                int gotoPageIndex = 1;
                int total = 0;
                PageBean page = new PageBean();
                page.setOffset(offset);
                page.setLength(length);
                page.setGotoPage(gotoPageIndex);
                page.setTotal(total);
                return page;
        }

        /**
         *  Get initialized paging information
         *
         * @return
         */
        public static PageBean initPage() {
                int length = Constants.PART_PAGE_PER_COUNT;
                int offset = 0;
                int gotoPageIndex = 1;
                int total = 0;
                PageBean page = new PageBean();
                page.setOffset(offset);
                page.setLength(length);
                page.setGotoPage(gotoPageIndex);
                page.setTotal(total);
                return page;
        }

        /**
         *  According to the incoming PageBean  total,offset, Has requested action, such as information    With the completion of this request, the correct pagination information    The requested actions including  

         *
         *  The previous page, next page  , Specific pages, etc.  

         *
         *
         *  The paging information including total data  , From the data fetch, fetch the number of bars, etc.  

         *
         *
         * @param page
         * @throws Exception
         */
        public static PageBean handle(PageBean page) throws Exception {
                int offset, curPage, begin, end, total, totalPage, gotoPage, length, startPage, endPage;
                offset = page.getOffset();
                curPage = page.getCurPage();
                begin = page.getBegin();
                end = page.getEnd();
                total = page.getTotal();
                totalPage = page.getTotalPage();
                gotoPage = page.getGotoPage();
                length = page.getLength();
                startPage = page.getStartPage();
                endPage = page.getEnd();

                if (gotoPage != 1) {
                        offset = length * (gotoPage - 1);
                }
                begin = offset + 1;
                if (offset + length > total)
                        end = total;
                else
                        end = offset + length;

                curPage = offset / length + 1;
                if (total % length == 0) {
                        totalPage = total / length;
                } else {
                        totalPage = total / length + 1;
                }

                startPage = curPage - 5;
                if (startPage < 1)
                        startPage = 1;
                endPage = startPage + 9;
                if (endPage > totalPage)
                        endPage = totalPage;
                if (end == 0)
                        begin = 0;

                page.setOffset(offset);
                page.setLength(length);
                page.setBegin(begin);
                page.setEnd(end);
                page.setCurPage(curPage);
                page.setEndPage(endPage);
                page.setGotoPage(gotoPage);
                page.setLength(length);
                page.setStartPage(startPage);
                page.setTotalPage(totalPage);
                page.setTotal(total);

                return page;
        }

        /**
         *  From the HttpServletRequest parameter    Get paging request value, set the  PageSelect In  

         *
         *
         * @param request
         * @return
         */
        public static PageBean getPageRequest(HttpServletRequest request) {
                int length = Constants.PART_PAGE_PER_COUNT;
                PageBean page = (PageBean) request.getAttribute(Constants.PART_PAGE_KEY);
                if (page == null) {
                        page = new PageBean();
                        page.setOffset(0);
                        page.setLength(length);
                        page.setGotoPage(1);
                }
                return page;
        }

        /**
         *  The paging information settings in the   request  In the Attribute  

         *
         * @param request
         * @param page
         *             The paging information
         * @throws Exception
         */
        public static void putPage(HttpServletRequest request, PageBean page) throws Exception {
                try {
                        request.setAttribute(Constants.PART_PAGE_KEY, page);
                } catch (Exception e) {
                        return;
                }
        }
}

PageTag.java link is constructed here, static links, according to their own needs may be

package com.itmg.tools.mytags;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts2.ServletActionContext;

public class PageTag extends TagSupport {
        private static final long serialVersionUID = -1122449622265941160L;
        // action url
        private String action;
        //  The current page number
        private Integer index;
        //  The maximum number of page numbers
        private Integer maxIndex;
        //  Each page displays up to number  

        private Integer size;
        //  Displays the number of page numbers in each group
        private Integer groupSize;
        // css
        private String styleClass;
        //  Template
        private String theme;

        @Override
        public int doStartTag() throws JspException {
                HttpServletRequest request = ServletActionContext.getRequest();
                JspWriter out = pageContext.getOut();
                String keywords = request.getParameter("keywords");
        String category = request.getParameter("category");
        String minPrice = request.getParameter("minPrice");
        String maxPrice = request.getParameter("maxPrice");
        String sort = request.getParameter("sort");
        String isAuction = request.getParameter("isAuction");
        if(isAuction == null)
                isAuction = "0";
                try {
                        if(category != null && !"".equals(category)){
                                if(minPrice != null || maxPrice != null)
                                        action += keywords+"/category/"+category+"/price/"+minPrice+"-"+maxPrice+"/";
                                else
                                        action += keywords+"/category/"+category+"/";
                        }else{
                                if(minPrice != null || maxPrice != null)
                                        action += keywords+"/price/"+minPrice+"-"+maxPrice+"/";
                                else
                                        action += keywords+"/";
                        }
                        StringBuffer html = new StringBuffer();
                        String url = null;
                        //  If there is only one page, you do not need paging
                        if (maxIndex > 1) {
                                //  Digital style   << prev 1 2 3 4 5 6 7 8 9 10 next >>
                                html.append("<div ");
                                if (styleClass != null) {
                                        html.append("class='" + styleClass + "'>");
                                } else {
                                        html.append(">");
                                }
                                if (index > 1) {
                                        //  The current is not the first group, to display  "<< Prev"
                                        // << Prev Return to the previous page  

                                        if((isAuction != null && !"0".equals(isAuction)) || (sort != null && !"0".equals(sort)))
                                                url = action + "/"+sort+"/"+isAuction;
                                        else
                                                url = action;

//                                      html.append("<a href='" + url + "'> First ペ ー ジ へ (disambiguation)  </a>&nbsp;");
                                        if((isAuction != null && !"0".equals(isAuction)) || (sort != null && !"0".equals(sort)))
                                            url = action + (index - 1) +"/"+sort+"/"+isAuction;
                                        else
                                                if(index>2)
                                                        url = action + (index - 1);
                                                else
                                                        url = action;
                                        html.append("<a rel=\"nofollow\" href='" + url + "'> ペ ー ジ へ before  </a>&nbsp;");
                                }
                                //  From the start page to begin  end Page, group  groupSize A number of pages  

                                int begin, end;
                                // groupSize Is not null, group show  , Otherwise show all
                                if (groupSize != null && groupSize < maxIndex) {
                                        //  Each group a number on the number of half  

                                        int halfGroupSize = (groupSize - 1) / 2;
                                        begin = (index - (halfGroupSize + 1)) > 0 ? (index - (halfGroupSize + 1)) : 1;
                                        end = (index + halfGroupSize) < maxIndex ? (index + halfGroupSize) : maxIndex;
                                        if (end == maxIndex) {
                                                if (maxIndex - groupSize < 1) {
                                                        begin = maxIndex;
                                                }
                                                begin = maxIndex - groupSize;
                                        } else if (begin == 1 && end < maxIndex) {
                                                end = maxIndex > groupSize ? groupSize : maxIndex;
                                        }
                                } else {
                                        begin = 1;
                                        end = maxIndex;
                                }
                                // groupSize Each group appears  

                                for (int i = begin; i <= end; i++) {
                                        if (index == i) { //  The current page to bolded
                                                html.append("<span\"current\">" + i + "</span>&nbsp;");
                                        } else {
                                                if((isAuction != null && !"0".equals(isAuction)) || (sort != null && !"0".equals(sort)))
                                                        url = action + i + "/"+sort+"/"+isAuction;
                                                else
                                                        if(i==1)
                                                                url = action;
                                                        else
                                                                url = action + i;

                                                html.append("<a rel=\"nofollow\" href='" + url + "'>" + i + "</a>&nbsp;");
                                        }
                                }
                                if (index < maxIndex) {
                                        // >>: Returns the next group of last page  

                                        // >: Returns the next  

                                        if((isAuction != null && !"0".equals(isAuction)) || (sort != null && !"0".equals(sort)))
                                                url = action + (index + 1) + "/"+sort+"/"+isAuction;
                                        else
                                                url = action + (index + 1);

                                        html.append("<a rel=\"nofollow\" href='" + url + "'> Time ペ ー ジ へ  </a>&nbsp;");

                                        if((isAuction != null && !"0".equals(isAuction)) || (sort != null && !"0".equals(sort)))
                                                url = action + maxIndex + "/"+sort+"/"+isAuction;
                                        else
                                                url = action + maxIndex;

//                                      html.append("<a href='" + url + "'> Final ペ ー ジ へ  </a>");
                                }
                                html.append("</div>");
                        }
                        out.write(html.toString());
                } catch (IOException e) {
                        e.printStackTrace();
                }
                return (SKIP_BODY);
        }

        public String getAction() {
                return action;
        }

        public void setAction(String action) {
                this.action = action;
        }

        public Integer getIndex() {
                return index;
        }

        public void setIndex(Integer index) {
                this.index = index;
        }

        public Integer getMaxIndex() {
                return maxIndex;
        }

        public void setMaxIndex(Integer maxIndex) {
                this.maxIndex = maxIndex;
        }

        public Integer getSize() {
                return size;
        }

        public void setSize(Integer size) {
                this.size = size;
        }

        public Integer getGroupSize() {
                return groupSize;
        }

        public void setGroupSize(Integer groupSize) {
                this.groupSize = groupSize;
        }

        public String getStyleClass() {
                return styleClass;
        }

        public void setStyleClass(String styleClass) {
                this.styleClass = styleClass;
        }

        public String getTheme() {
                return theme;
        }

        public void setTheme(String theme) {
                this.theme = theme;
        }

}

In the action to do the following definition:

// The paging information
                PageBean page = new PageBean();
                if (request.getParameter(Constants.PART_PAGE_PAGESEARCH) != null && request.getParameter(Constants.PART_PAGE_PAGESEARCH).equals("true")) {
                        page = PageHandler.initPage(request);
                }
                page.setLength(Constants.PART_PAGE_PER_COUNT_10);
                if (index != null) {
                        page.setGotoPage(index);
                } else {
                        page.setGotoPage(1);
                }

jsp page:

<div>
                                <div>
                                        <mytag:page index="${resultView.page.curPage}" maxIndex="${resultView.page.totalPage}" action="${pageContext.request.contextPath}/word/" size="${resultView.page.length}" styleClass="page_styl" groupSize="12"></mytag:page>
                                </div>
                      </div>

css settings:

#page {
        margin: 40px auto;
        margin-bottom: 25px;
        text-align: center;
}

div .page_styl {
        text-align: center;
        padding-right: 1px;
        padding-left: 1px;
        padding-bottom: 3px;
        margin: 3px;
        padding-top: 3px;
        text-align: center;
        font-size: 14px;
}

div .page_styl a {
        border-right: #fff 1px solid;
        padding-right: 1px;
        border-top: #fff 1px solid;
        padding-left: 1px;
        padding-bottom: 1px;
        margin: 2px;
        border-left: #fff 1px solid;
        color: #0032ab;
        padding-top: 1px;
        border-bottom: #fff 1px solid;
        text-decoration: underline
}

div .page_styl span.current {
        border-right: #fff 1px solid;
        padding-right: 1px;
        border-top: #fff 1px solid;
        padding-left: 1px;
        font-weight: bold;
        padding-bottom: 1px;
        margin: 2px;
        border-left: #fff 1px solid;
        color: #000;
        padding-top: 1px;
        border-bottom: #fff 1px solid;
        /*      background-color: #d5d5d5;*/
}

div .page_styl span.disabled {
        border-right: #eee 1px solid;
        padding-right: 5px;
        border-top: #eee 1px solid;
        padding-left: 5px;
        padding-bottom: 2px;
        margin: 2px;
        border-left: #eee 1px solid;
        color: #ddd;
        padding-top: 2px;
        border-bottom: #eee 1px solid
}

Finally, business logic tier:

page.setTotal(searchResult_temp.size());
page = PageHandler.handle(page);
相关文章
  • tld tag page address 2010-04-17

    my-tag.tld <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <

  • In the jsp page using oscache tag page cache implementation configurable 2010-11-25

    In the jsp page using oscache tag page cache implementation configurable Articles Category: Java Programming Recent study oscache relevant content, write something as consolidation If you use the following tag in the jsp Java code <cache:cache key=&quo

  • JSTL_EL__ tag Jsp_ page address 2010-04-26

    <html:select property="clerkId" value="${task.employeeByClerkId.empId}"> <option value="0">-- Please select the employee --</option> <logic:present name="empList"> <html:options collection

  • Jstl tag page background static method call, write custom tags 2010-07-25

    Recently done a community project, using the familiar SSH model, the page would have to use struts2 tag standards are uniform, but the project team to use the jstl tag some people, they encounter some problems. For example, when shown in the foregrou

  • struts custom tag page 2011-01-05

    Tag files (into the WEB-INF directory): <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd&

  • dedecms 5.5 pseudo-static implementation tag page 2011-03-31

    A few days ago read tag Label pseudo-static just had an idea, the page URL but also ended up as pseudo-static calculations, here's how: The first step: 1. Open arc.taglist.class.php 2. Find the way function GetCurUrl() { if(!empty($_SERVER["REQUEST_U

  • JavaScript page address 2010-03-17

    / / Paging object, method call by the following / / New PageManage (). Process (current_page, total_record_num, every_page_nums, func_name, page_display_num); / / Current_page for the current page number, total_record_num the total number of records,

  • DWR js undefined - Websphere running under the wrong page address 2010-06-05

    DWR1.0, jdk1.4, websphere6.0 environment dwr run in WebSphere conclusions: 1. Tomcat is weak inspection, when only a dwr.xml file And there is no <signatures> attribute dwr.xml time inside the dwr configuration in web.xml <init-param> <para

  • Struts2 tag page for Parameters 2010-04-27

    <s:property value="#request['addService']"/>

  • JSP custom tag TLD documentation Xiangjie 2010-03-25

    Write a tld paging label, but a number inside a specific meaning forgot, - -! So a handful of Baidu. To clarify the meaning of some of the labels commonly used, as explained ================================================== ============== The first

  • pager tag library (page display) Xiangjie 2010-03-31

    A brief Pager-taglib, supports a variety of styles page display. In fact she is a Jsp tag library, in the JSP page of information displayed on a label designed by different combinations of these labels would form a variety of different page page, dif

  • php to get page of the url address 2010-09-24

    More useful <?php $urlshang = $_SERVER['HTTP_REFERER']; // You can get the previous address $urldan = $_SERVER['PHP_SELF']; // Get the current page address $urlcan = $_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$_SERVER[

  • php in the url address to get the previous page 2010-09-24

    More useful <?php $urlshang = $_SERVER['HTTP_REFERER']; // You can get the previous address $urldan = $_SERVER['PHP_SELF']; // Get the current page address $urlcan = $_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$_SERVER[

  • 2009-12-13 Chuan Chi podcast java web - the traditional label with a simple tag (Reprinted) 2010-04-10

    In addition to JavaMail JavaWeb today is part of the last day, there are three days is to be a small project. Before learning to string together all the knowledge, prepare for high-level segment. Hei hei! Finally to the advanced section! Today, the m

  • Struts2 + Spring + iBatis on the web application of best practices Series 5 (page articles) 2010-03-29

    Paging is also a frequent topic of discussion all, on-line there were a lot of paging method of introduction, but often merely confined to the web layer or data access layer of a page component, for a typical three-tier web applications I have not se

  • Custom JSTL tag function, convenient for personal use 2010-03-26

    Custom JSTL tag function to facilitate the call page, by calling the function returns the data page is displayed. Simple, convenient, commonly used in the development to the time. The following provinces of view by showing the steps of: The first ste

  • HTML Reference Manual (tag. Properties and events) 2010-04-20

    HTML tags Tag Description DTD <!--...--> Definition Notes . STF <!DOCTYPE> Document Type Definition . STF <a> Defined anchor . STF <abbr> Definition of abbreviations . STF <acronym> Just take the definition of the acronym . S

  • Placeholder image address access issues 2010-05-09

    Causes: Believe will be the first to be used extjs of this issue: 1. Blank image problem Need to set Ext.BLANK_IMAGE_URL-based machines Ext blank image address, or if the network would not cross the interface. Main advantage of the fact of a blank im

  • Original: Web Analytics Web Analytics Basics Page Views (PV) - page views 2010-07-05

    Page Views (hereinafter referred to as PV) - page views Many people think that in the Web Analytics, PV is a very simple Metrics, I used to think so. But with the deepening of understanding, I found the correct order to understand the PV, First you h

  • JSP tag library in-depth study 2010-07-14

    Tag handler and tag additional information needs to be positioned in the JSP container class loader can find it. Tag library descriptor can be specified in the URL location of the symbol means. Taglib Tag library Tags are defined and distributed in a