Title: How to get limited page numbers visible in pagenation list to display a list of items?
Tags: jsp;jstl
Question: ```<c:if test="${paging.pageCount &gt; 1}"&gt;
<c:if test="${not empty searchkey}"&gt;
<c:set var="pagingpath1" value="&amp;key=${searchkey}&amp;value=${searchvalue}" /&gt;
</c:if&gt;
  <div style=" background:#f5f5f5; border:1px solid #dedede; height:30px; width:985px;  margin:20px auto"&gt;
        <div class="pagDiv_1"&gt;<a&gt;Results:<span&gt;<c:out value="${ paging.page }"&gt; - </c:out&gt; - <c:out value="${ paging.pageCount }"&gt;</c:out&gt; ( total: <c:out value="${ paging.count }"&gt;</c:out&gt; )</span&gt;</a&gt;</div&gt;
    <div class="page-nav"&gt;
                <a&gt;Pages:</a&gt;
                <c:choose&gt;
                <c:when test="${paging.orderStatus}"&gt;
                <c:set var="pagingpath" value="&amp;order=${paging.order}&amp;dir=${paging.direction}"&gt;
                </c:set&gt;
                </c:when&gt;
                <c:otherwise&gt;<c:set var="pagingpath" value=""&gt;</c:set&gt;</c:otherwise&gt;
                </c:choose&gt;
                <a class=lftarrow href="#"&gt;Previous &amp;#9668;</a&gt;
                <c:forEach var="pid" varStatus="status" begin="1" end="${paging.pageCount}" step="1"&gt;
                <c:choose&gt;
                    <c:when test="${pid == paging.page}"&gt;<span class="cur-page"&gt;<b&gt;${ pid }</b&gt;</span&gt;<label&gt;|</label&gt;</c:when&gt;
                    <c:otherwise&gt;<a class="page" href="consultant_list.htm?p=${pid}${pagingpath1}&amp;selectiontype=${selectiontype1}&amp;searchtext=${textbox1}"&gt;${ pid }</a&gt;<label&gt;|</label&gt;</c:otherwise&gt;
                </c:choose&gt;
                </c:forEach&gt;
                                            <a class=lftarrow href="#"&gt;&amp;#9658; Next</a&gt;

    </div&gt;

  </div&gt;
  </c:if&gt;
```



The image attached has the listing page in which I am working .

The code snippet is to display the pagenation in the footer.

How to make only say 4 page numbers visible at once and on click of "Next" the other pages must be visible?

Comment: Just a tip: don't do that in JSP/JSTL/EL code. Prapare the work for the view in a controller, in Java. Regarding the code, it's just a matter of only generating the links for some pages around the current one, and potentially a link for the first and last one. integer arithmetics.

Comment: Thanks ..me too thinking the same.any best logical idea for doing it ?


Here is another answer: You can create a Tag for this which can display only relevant pages (few around the current page and start &amp; last page), which can be used at multiple places and will be cleaner approach as well.

You can create a tag, which will accept these parameters: 


a) the url you want to hit on selection of each page. 
b) the number of links you want to show at a time, say 10. 
c) total page size. 


In this tag you can add this code to show only few page numbers (say 10) with first &amp; last page link. Now this thing can be used as a component which can be used in various places of your application.

Comment for this answer: You can create a tag, which will accept these parameters: a) the url you want to hit on selection of each page. b) the number of links you want to show at a time, say 10. c) total page size. In this tag you can add this code to show only few page numbers (say 10) with first & last page link. Now this thing can be used as a component which can be used in various places of your application.
Comment for this answer: I dint get you .. can u re-explain

Here is another answer: DisplayTag is a wonderful little library that makes what you want to do easy..

http://www.displaytag.org/1.2/

Alternatively, if the size of your dataset's aren't very large in size (bytes) the following Jquery library is also cool:

http://datatables.net/


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:02/01/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<jsp><jstl>', 'Title': 'How to get limited page numbers visible in pagenation list to display a list of items?', 'ViewCount': 1203, 'id': 9095604, 'user_AboutMe': '<p>I am a Software Engineer positioned as Java Developer.</p>\n', 'user_AccountId': 288203.0, 'user_DisplayName': 'Meenakshi', 'user_Reputation': 468.0, 'user_Views': 278.0, 'user_id': 588481.0}}