<% if (firstPage != currentPage) { %>
First
<% } %>
<% if (currentPage > firstPage) { %>
Previous
<% } %>
<% if (currentPage - 3 > firstPage) { %>
...
<% } %>
<% for (p=currentPage-3; p<=currentPage+3; p++) { %>
<% if (p < firstPage || p > lastPage) continue %>
<% if (currentPage == p) { %>
<%= p+1 %>
<% } else { %>
<%= p+1 %>
<% } %>
<% } %>
<% if (currentPage + 3 < lastPage) { %>
...
<% } %>
<% if (currentPage < totalPages) { %>
Next
<% } %>
<% if (lastPage != currentPage) { %>
Last
<% } %>