12 Replies Latest reply: Mar 30, 2007 1:50 AM by 807606 RSS

    hw to achieve the nxt int number???

    807606
      in my jsp am getting the list of rows frm DB, i need to set ten rows per page with the page number at the bottom, hw can i achieve it...

      i think pagination is d rite but i dont know how to do??? iam using jsp and servlet..


      <%
           int pgnm = searchList.size() / 10;
           System.out.println("PAGES IN JSP--->>> "+pgnm);

      %>
      and nw i got the size of the list, but if the list has 33 records its shows 3 pages, hw can i achieve it as nxt int???

      thanks in advance...
        • 1. Re: hw to achieve the nxt int number???
          807606
          Change your code..

          <%
          int pgnm = searchList.size() / 10;
          int mod = searchLIst.size()%10;
          if(mod>0)
          pgnm++;
          System.out.println("PAGES IN JSP--->>> "+pgnm);

          %>

          This should possibly do it..
          • 2. Re: hw to achieve the nxt int number???
            807606
            hei thanks, it worked.....
            wats the func of % ???

            wen ever the page gets increased i need to get the page numbers??? how can i do this??
            • 3. Re: hw to achieve the nxt int number???
              807606
              % implies modulus operation.
              It returns you the remainder..


              wen ever the page gets increased i need to get the page numbers??? how can i do this??
              What does this mean??
              • 4. Re: hw to achieve the nxt int number???
                807606
                i hav a search box wen i enter some name n click submit it should check the db n return the matches in the page

                for eg: my query matches 50 records in DB(sybase),
                it should 10 in the first page and the nxt 10 in 2nd page n go on...

                i read in the web tat pagination would solve this, but i dont know pagination can u help me out....


                here is my jsp code.... dont know hw to proceed nxt....

                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

                <HTML>
                <HEAD>
                <%@ taglib uri="/WEB-INF/pagination.tld" prefix="pagination-tag"%>
                <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
                     pageEncoding="ISO-8859-1"%>
                <%@ page import="java.util.*" %>
                <%@ page import="com.INFO.*" %>
                <%@ page import="com.DAO.*" %>
                <jsp:useBean id = "searchList" scope="request" class="java.util.ArrayList"/>
                <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                <META name="GENERATOR" content="IBM Software Development Platform">
                <META http-equiv="Content-Style-Type" content="text/css">
                <LINK href="theme/Master.css" rel="stylesheet"
                     type="text/css">
                <TITLE>SearchResult.jsp</TITLE>
                </HEAD>
                <script>
                function docancel(act){
                document.backfrm.action.value=act;
                document.backfrm.submit();
                }
                </script>
                <BODY>
                <form action="SearchServlet" method="GET" name="backfrm">
                <input type="hidden" name="action" value="" />
                <input type="hidden" name="pageno" value="" />

                <table>
                <%
                SearchDAO searchDAO = new SearchDAO();
                %>

                <%
                Iterator i = searchList.iterator();
                while(i.hasNext()){
                SearchInfo searchInfo = (SearchInfo)i.next();
                %>
                <%System.out.println("SIZE IN JSP------------>>>>>> "+searchList.size());%>
                <% System.out.println("name in jsp----------->>>>"+searchInfo.getName());%>
                <%
                     int pgnm = searchList.size() / 10;
                     int mod = searchList.size() % 10;
                     if(mod>0)
                     pgnm++;
                     System.out.println("PAGES IN JSP------------>>>>>> "+pgnm);
                %>
                <tr>
                <td><%=searchInfo.getName()%></td>
                <%


                %>
                </tr>
                <%}%>
                <tr>
                <td><INPUT name=Submit Value="Back" type="button" OnClick="docancel('cancel')"/></td>
                </tr>
                </table>
                </form>
                </BODY>
                </HTML>
                • 5. Re: hw to achieve the nxt int number???
                  807606
                  When the first page is displayed use a link or button to go to the next page.
                  While moving to the next page pass the current record count to the next page so that it can use it to index the records.
                  For eg. if the count passed is 10 start from the 11th record on the next page.
                  • 6. Re: hw to achieve the nxt int number???
                    807606
                    <%
                         int count = 0;
                         int pgnm = searchList.size() / 10;
                         int mod = searchList.size() % 10;
                         if(mod>0)
                         pgnm++;
                         System.out.println("PAGES IN JSP------------>>>>>> "+pgnm);
                         count = searchList.size();
                         if(count>10)
                         System.out.println("count IN JSP------------>>>>>> "+count);
                    %>
                    here i am getting the size of the count.....

                    how can i limit the records to display 10 per page n hw can i pass the count value further???
                    • 7. Re: hw to achieve the nxt int number???
                      807606
                      While displaying the records only display ten of them.
                      And then when the NEXT button is clicked, pass on the count while making the call in the "action" field..
                      • 8. Re: hw to achieve the nxt int number???
                        807606
                        hw can i diaplay only ten records in my first page????
                        • 9. Re: hw to achieve the nxt int number???
                          807606
                          Bingo!!!!

                          PreparedStatement.setMaxRows(10);

                          using this i can limit my row count....
                          • 10. Re: hw to achieve the nxt int number???
                            807606
                            Your serlvet should only place ten entries into the search results table. Pass it a page number, or first row number as a parameter. Depending on the database you may be able to add a LIMIT clause to the select statement so that the database only returns a single page. The navigation buttons on the resuts page will call the servlet again with the same search criteria but a new page number.
                            • 11. Re: hw to achieve the nxt int number???
                              807606
                              iam using sybase as my DB i think there is no LIMIT clause in it....

                              plz explain elaboratly....

                              thanks
                              • 12. Re: hw to achieve the nxt int number???
                                807606
                                There does exist a row limit clause. Please refer the usage..