Paging in jsp

please sir
i need ur help
to display large number of items retrived from database
in page by page style
for ex display 10 records in each page then click next to view the second 10 records asd soo on
thank u

First I will suggest you to use the "LIMIT" clause in your SQL to limit the num. of record you retrieve for each page. ("LIMIT x,y" can be used to retrieve only y rows, starting at the (x+1)th row)
So each time you go to the page, the starting row will be determined by a parameter, say, pageStartIndex, which you will get from request.getParameter("pageStartIndex"). You will set it to x as the page start index.
Then you will try to create those "Next" & "Previous" link by passing the new pageStartIndex in the URL. You will have to do some manupilation on the new pageStartIndex.
e.g. assume the current pageStartIndex = 0 and you want to display 10 rows per page.
Then in the "Next" link, you will pass a variable "pageStartIndex" which has a value of 0 + 10 = 10
So your "Next" link will be something like:
label
Of course, the value 10 in the link has to be computed dynamically.
Put everything together you will have something like this:
<%
String pageStartIndex = request.getParameter
("pageStartIndex");
String rowPerPage = request.getParameter("rowPerPage");
if (pageStartIndex == null) pageStartIndex = "0";
if (rowPerPage == null) rowPerPage = "10";
int nextPageIndex = Integer.parseInt(pageStartIndex) + Integer.parseInt(rowPerPage);
%>
<a href="samePage.jsp?pageStartIndex=<%=Integer.toString(nextPageIndex)%>">Next</a>

Similar Messages

  • Paging in JSP using SQL SERVER 2000

    Hi!!
    How to do paging in JSP using SQL SERVER 2000.
    In my SQL we can fire query like
    ResultSet resultado = declaracao.executeQuery("Select * from tbl_livro limit 20,5 ");
    It means that it fetches 20 onwards 5 records..
    how to do same thing in SQL SERVER 2000 please help it's pretty urgent

    here is the link for paging, what i already post reg this topic
    http://forum.java.sun.com/thread.jspa?threadID=5194183try to avoid multipost next time

  • Paging in JSP using

    Hi!!
    How to do paging in JSP using SQL SERVER 2000.
    In my SQL we can fire query like
    ResultSet resultado = declaracao.executeQuery("Select * from tbl_livro limit 20,5 ");
    It means that it fetches 20 onwards 5 records..
    how to do same thing in SQL SERVER 2000 please help it's pretty urgent

    http://forum.java.sun.com/thread.jspa?threadID=5194183

  • How to make  paging in JSP?

    I would like to know how to make paging in JSP?
    PLEASE HELP ME !

    It is much easier , if you use MVC framework, you can store
    results in session appropriate action to servlet, it will serve page by page.

  • Paging in JSP(Scriptlets) help-me! help-me! help-me!

    Somebody can order an example of paging in JSP. does not obtain to make the paging.... Please, somebody can help.....� an urgency case me! In case that somebody has some example please, [email protected] orders pro email If possivel in Scriptlets
    Very Obliged!

    <%@ page import="java.sql.*" %>
    <%@ page errorPage="err.jsp" %>
    <%
    By VendeW and Shibayama
    %>
    <html>
    <body>
    <center>
    <h2>Pagina��o usando JSP e MySQL</h2>
    <table border="2">
    <tr bgcolor="tan">
    <th>id</th><th>Titulo</th><th>Image</th><th>Descri��o</th></tr>
    <%
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection conexao = DriverManager.getConnection("jdbc:odbc:book");
    Statement declaracao = conexao.createStatement();
    Statement declaracao2 = conexao.createStatement();
    int limitePorPagina = 5;
    ResultSet resultado = declaracao.executeQuery("Select * from tbl_livro limit " + request.getParameter("pr") + "," + String.valueOf(limitePorPagina));
    ResultSet rs2 = declaracao2.executeQuery("Select count(*) as c from tbl_livro");
    rs2.next();
    int totalregs = Integer.parseInt(rs2.getString("c"));
    %>
    <b>Total de Registros: </b><%=totalregs%>
    <%
    int totalpgs = Math.round(totalregs / limitePorPagina);
    out.write("<b>P�ginas:</b> " + totalpgs);
    if ((totalregs % limitePorPagina) > 0) totalpgs++;
    int pr = Integer.parseInt(request.getParameter("pr"));
    try {
    while (resultado.next()) {
    String id = resultado.getString("id_livro");
    String nm = resultado.getString("nm_livro");
    String img = resultado.getString("image");
    String desc = resultado.getString("desc_livro");
    %>
    <tr>
    <td><%=id%> </td>
    <td><%=nm%> </td>
    <td><%=img%> </td>
    <td><%=desc%> </td>
    </tr>
    <%
    }//while (resultado.next())
    %>
    </table>
    <%
    }//try
    catch (SQLException e) { out.println("SQL Error" + e); }
    if (pr > 0) {
    %>
    [Primeira P�gina] 
    <a href="?pr=<%=pr-limitePorPagina%>">[Anteriores]</a> 
    <%
    }//if (pr > 0)
    if (pr < (totalpgs * limitePorPagina) - limitePorPagina) {
    %>
    <a href="?pr=<%=pr+limitePorPagina%>">[Pr�ximos]</a> 
    <a href="?pr=<%=(totalpgs * limitePorPagina) - limitePorPagina%>">[Ultima P�gina]</a> 
    <%
    }//if (cont < totalpgs)
    %>
    </center>
    </body>
    </html>

  • How to do paging in JSP

    Hi,
    I am new to Java. I want to do paging on JSP pages. I am using Oracle as database.and I am getting 1000 records on firing my query.
    Plz help me its very urgent.
    Thanks in advance,
    Devom

    http://www.javaworld.com/javaworld/jw-07-2004/jw-0726-pagination.html
    http://displaytag.sourceforge.net/11/tut_externalSortAndPage.html
    http://jsptags.com/tags/navigation/pager/index.jsp

  • Paging in JSP ! HELP! HELP! HELP!

    somebody can order an example to me of paging of results in JSP... or tutorial address that has some scritpt and. since already I am thankful!
    [email protected]

    If you are interested in creating some type of paging functionality you will need a few things. First, i will assume you have some set of data that you want to page. Let's say you have an array of Objects that has 100 total elements.
    You will most likely define a pageSize value that defines how many elements to display on the current page. You will also want to define a pageNumber to represent the current page that you are on.
    So lets say that you have a pageSize = 10.
    You should define some Java method in a class that has access to the complete array, which takes the pageSize and pageNumber as parameters, and returns an array of the same type.
    For example, lets say you have a class called EmployeeSet
    public class EmployeeSet
    private Employee[] totalEmployeeSet;
    public void setEmployeeSet
    //some code that populates the totalEmployeeSet array
    public Employee[] getEmployeeSet()
    return totalEmployeeSet;
    public Employee[] getCurrentEmployeePage(int pageSize, int pageNumber)
    // some logic to check that parameters are within valid range
    Employee[] currentEmployeeSet = new Employee[pageSize];
    //now store the current range into your current set
    //loop through the totalEmployeeSet starting at the correct
    //point (pageNumber*pageSize), and store each element
    //into the currentEmployeeSet
    return currentEmployeeSet;
    I left out some important logic to determine whether the inputs to the method are valid or not, and whether the current page can display 'pageSize' elements or not. I am sure you can figure that out.
    I hope this helps some.
    -Dras

  • Paging in jsp servlet..

    Hi ppl,
    i hav 1000's of record in my DB(sybase) wen the jsp page loads it shoud show the first 10 records followed by the page numbers like 1,2,3..... wen i click 2 it should return nxt 10 records frm DB... like till the last record... hw can i implement paging in this.
    iam doing this in jsp n servlet. no hibernate....
    Thanks in advance....
    Regards Jaideep

    One relatively easy way would be to use a JSP tag, like this one.

  • Resultset paging using jsp

    I am creating a small search program using jsp. I want to know how can I implement paging using JDBC.
    It is very easy using asp. In asp only a specified no. or records can be retrieved from database using combination of PageSize and AbsolutePage properties of Recordset Object.
    In jdbc I think there is no such method available. Do I have to use database base specific options to limit the number of records returned like limit keyword in mysql.
    Only way I can think of is to create a resultset object and store it in session and then use the absolute() method of the resultset object to go to a specific record and then next(). But still all records have to returned by db and have to be kept in memory and not only specific no. of records (e.g 10 per page).
    If I doesn't store the recordset in session then every time this search page is accessed, a new recordset is returned with all records. I then have to determine how many records to skip according to page selected in the query string and then use absolute() method of recordset to go to specific record. And then loop, say ten times to display 10 records. Again when next is clicked same procedure is repeated. Here retrieving all records every time page is accessed is very expensive operation.
    In my case even this isn't possible because I am using jdbc odbc bridge, which is not allowing scrollable resultset and jvm is throwing exception in native code. Without scrollable resultset I cannot know how many records are returned. If I try to count using a loop and resultset's next() then I don't have any way to go back to first record again when I actually want to retrieve records to display. Only other way to count the records is executing query twice which isn't very good as records may have been added or deleted between two calls.
    Am I wrong anywhere above?
    If not then question is, can this be done efficiently with jdbc without using any database specific keywords?
    If yes then which method can be used on a busy web site with huge database.
    --Sukhwinder Singh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    This may help: http://www.powerobj.com
    providing "advice" in this manner is unethical and unhelpful. if you feel a product you are selling would be good for someone you should at the very least disclose your interest in the selling of said product.
    the blatant ad you posted in the JavaServer Pages forum at least makes it clear that you are selling a product. this post does not make that clear and it really should be.

  • How to use IBatis paging in jsp?

    I'm a new comer in IBatis.If I query the database using the method "executeQueryForList" how to display the record in jsp (for example 10 record) and display next 10 record? I means how to create page number in jsp for user click?
    If someone used it please help me.
    It is best give me an example.
    Thks

    Any idea?
    But I think the method "executeQueryforPaginatedList" will be better.Because it has associated method "nextPage(), previousPage(), gotoPage(),isMiddlePage(), isLastPage(), isNextPageAvailable(),".
    What I want to know is how to display the page number according to the resultset.For example,If I want to display this in jsp:
    "<<back 1 2 3 4 last>>>"
    How to display the number "1,2,3,4"?
    I means that if I query 10 record per time how to display it in jsp?
    :(

  • Paging

    Hi,
    I would like to know which the best form of if making paging using jsp, using only tomcat in my server.
    Thanks

    Hi,
    You can implement paging using CachedRowSet, go thru the link below for more details.
    http://www.javaworld.com/javaworld/jw-02-2001/jw-0202-cachedrow.html
    cheers,
    Rkanth

  • Servlet could nt able to Display the Result Page By Page ( Paging Problem)

    Hi, I want to display my result set Page by page... i wrote the code but it is not working properly... just it is showing intial record page(i.e 0 to 5) and page number links, But when i click on those number hyper links, just it is coming empty pages...
    plz help me out Thanks a lot in advance..... and my code is
    package tauvex;
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.sql.DriverManager.*;
    public class TauvexDataServlet extends HttpServlet {
    Connection con=null;
    Statement statement=null;
    ResultSet resultset=null;
    public void init(ServletConfig config) throws ServletException {
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://localhost/fitstestdb","root","");
    } catch (ClassNotFoundException ex) {
    System.err.println("ClassNotFoundException: " + ex.getMessage());
    throw new ServletException("Class not found Error");
    } catch(java.lang.InstantiationException ie) {
    System.out.println("instantiation exp:"+ie);
    } catch(java.lang.IllegalAccessException ia) {
    System.out.println("illegalaccess exp:"+ia);
    } catch (SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    protected void processRequest(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    +*// From Here My problem Starts*_+ 
    // Code For Paging starts
    int pages=0;
    try{
    Connection ocon = null;
    Class.forName("com.mysql.jdbc.Driver");
    ocon = DriverManager.getConnection("jdbc:mysql://localhost/fitstestdb","root","");
    Statement stmtt = ocon.createStatement();
    ResultSet rc = stmtt.executeQuery("Select count(*) from FitsData ");
    rc.next();
    pages = rc.getInt(1);
    out.println("Count of Records : " + pages + "<br>");
    catch (ClassNotFoundException ex) {
    System.err.println("ClassNotFoundException: " + ex.getMessage());
    throw new ServletException("Class not found Error");
    } catch (SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    int cPage;
    cPage = (pages / 5) + 1;
    if ((cPage * 5) + 1 >= pages)
    cPage++;
    out.println("Count of Pages : " + (cPage - 1) + "<br><p><p>");
    int p;
    for(p = 1; p < cPage ; p++)
    out.println("<a href=TauvexDataServlet?mv=" + p + ">"+ p +"</a> | ");
    out.println("<hr>");
    // paging
    int cpage;
    int currentRs;
    String pt;
    pt = request.getParameter("mv");
    if (pt == null)
    currentRs = 0;
    else
    cpage = Integer.parseInt((String)pt);
    currentRs = 5 * (cpage - 1);
    out.println(cpage + "<br>");
    //Paging Code End here
    *// My problem ends here ...!!!*
    String RA=new String();
    String DEC=new String();
    String DATE=new String();
    String DATE1=new String();
    String FILTER=new String();
    String Radious=new String();
    String ShowRA=null;
    String ShowDEC=null;
    String ShowFile=null;
    String ShowQuery=null;
    String ObservationDates=null;
    String Telescope=null;
    String Filter=null;
    RA=request.getParameter("RA");
    DEC=request.getParameter("DEC");
    DATE=request.getParameter("DATE");
    DATE1=request.getParameter("DATE1");
    FILTER=request.getParameter("FILTER");
    Radious=request.getParameter("Radious");
    ShowRA=request.getParameter("ShowRA");
    ShowDEC=request.getParameter("ShowDEC");
    ShowFile=request.getParameter("ShowFile");
    ShowQuery=request.getParameter("ShowQuery");
    ObservationDates=request.getParameter("ObservationDates");
    Telescope=request.getParameter("Telescope");
    Filter=request.getParameter("Filter");
    String query = "SELECT * " +
    " FROM FitsData limit "+currentRs+",5;";
    try {
    Statement statement=con.createStatement();
    ResultSet resultset=statement.executeQuery(query);
    if(ShowQuery != null && "on".equals(ShowQuery))
    out.println("<font size=4 color=black>The Selected Query is :</font><br/>");
    out.println("<font>");
    out.println(query);
    out.println("</font>");
    out.println("<hr>");
    if(resultset.next()!=false) {
    out.println("<html><head>");
    out.println("</head><body>");
    out.println("<table cellspacing=1 cellpadding=1 border=1>");
    out.println("<tr>");
    if(ShowFile != null && "on".equals(ShowFile))
    out.println("<td> Filename </td>");
    if(ShowRA != null && "on".equals(ShowRA))
    out.println("<td> RA_START </td>");
    if(ShowRA != null && "on".equals(ShowRA))
    out.println("<td> RA_END </td>");
    if(ShowDEC != null && "on".equals(ShowDEC))
    out.println("<td> DEC_START </td>");
    if(ShowDEC != null && "on".equals(ShowDEC))
    out.println("<td> DEC_END </td>");
    if(Telescope!=null && "on".equals(Telescope))
    out.println("<td> TELESCOPE </td>");
    if(ObservationDates !=null && "on".equals(ObservationDates))
    out.println("<td> STARTOBS </td>");
    if(ObservationDates !=null && "on".equals(ObservationDates))
    out.println("<td> ENDOBS </td>");
    if(Filter!=null && "on".equals(Filter))
    out.println("<td> FILTER </td>");
    out.println("</tr>");
    while(resultset.next())
    Object o1 = resultset.getObject(1);
    Object o2 = resultset.getObject(2);
    Object o3 = resultset.getObject(3);
    Object o4 = resultset.getObject(4);
    Object o5 = resultset.getObject(5);
    Object o6 = resultset.getObject(6);
    Object o7 = resultset.getObject(7);
    Object o8 = resultset.getObject(8);
    Object o9 = resultset.getObject(9);
    out.println("<tr>");
    if(ShowFile != null && "on".equals(ShowFile) && o1 != null)
    out.println("<td>"+o1+"</td>");
    if(ShowRA != null && "on".equals(ShowRA) && o2 != null)
    out.println("<td>"+o2+"</td>");
    if(ShowRA != null && "on".equals(ShowRA) && o3 != null)
    out.println("<td>"+o3+"</td>");
    if(ShowDEC != null && "on".equals(ShowDEC) && o4 != null)
    out.println("<td>"+o4+"</td>");
    if(ShowDEC != null && "on".equals(ShowDEC) && o5 != null)
    out.println("<td>"+o5+"</td>");
    if(Telescope!=null && "on".equals(Telescope) && o6!=null)
    out.println("<td>"+o6+"</td>");
    if(ObservationDates !=null && "on".equals(ObservationDates) && o7!=null)
    out.println("<td>"+o7+"</td>");
    if(ObservationDates !=null && "on".equals(ObservationDates) && o8!=null)
    out.println("<td>"+o8+"</td>");
    if(Filter!=null && "on".equals(Filter) && o9!=null)
    out.println("<td>"+o9+"</td>");
    out.println("</tr>");
    out.println("</table>");
    out.println("<br>");
    out.println("</body>");
    out.println("</html>");
    else {
    out.println("NO MATCHING RECORDS FOUND");
    } catch(java.sql.SQLException sqle) {
    System.out.println("sql exception:"+sqle);
    out.close();
    protected void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    protected void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    public String getServletInfo() {
    return "Short description";
    }

    I also did a Servlet Paging but I later found a Paging example that used MVC architecture which I found to be more efficient.
    This post has a good example in this link: http://forums.devshed.com/java-help-9/paging-in-jsp-85968.html?p=382695#post382695
    After I downloaded the example I made alot of changes and got rid of the scriptlets in the JSP and brought it more up to date using JSTL.
    Also check out a pre-built tag: http://displaytag.sourceforge.net/

  • Logical problem using vectors

    Hi and Happy New Year,
    I have a vector in my java application which contains a number of elements that is not fix which means each time the number of elements might change.
    I want to retrieve the elements of the vector 3 by 3 its like table records paging in jsp , asp or php
    - lets say this time i've got 10 elements in my vector , I have to JButtons previous_3 and next_3
    - The first time the program runs I want to get the first three elements of the vector (0 to 2)
    - By clicking on the next_3 button I want to get the next 3 ( 3 to 5) and so on... providing that the exist
    - By clicking on the privious_3 button I want to get the previous 3 ( 0 to 2) in this instance and so on... providing that the exist
    Can anyone give me a hint as how to solve this problem at least give me some ideas cause i am lacking of ideas my brain is frozen, I know that is it more a logical problem that a programming one
    I 've done this kind of thing in Asp and PHP but as I am new to Java
    I just can not figure out how to tackle this issue

    You may want to use the modulus function.
    lets look at an example.
    pseudo code
    vector v = new vector()
    v.size = 10; //lets say there are 10 elements in the vector
    int n = 3; // you want to jump maximum 3 elements each time
    // you can jump 3.3 times before running outide the scope
    // of the vector, well after the third time you must check
    // how many elements that is left in the vector, this is
    // done by modulus n%10 = 1, this means that the last time
    // you can not jump more than 1 element.
    I have to go now so I cant give you any code to cope with the problem, Ill be back in 3 hours, maybe I can give a good axample, but this outline is the way to go.
    TheLaw

  • Pagination using pager tag library (logical groupings)

    I'm currently trying to achieve pagination using the pager tag library provided by jsptags.com.
    Instead of the usual breaking up the records into a fix number to be displayed per page, I need to display these records by grouping per page. E.g., my records are grouped by countries, so each group varies in size.
    I would not be accessing the database directly from the JSP page, in fact, the JSP page will get a collection of the objects that I want to display per page.
    Has anyone done anything like this before? Would appreciate very much if you could share with me how you implement this.
    Thanks!

    Hi there,
    I am wondering if you found the solution for your question with paging in JSP. if so i will really appreciate if you can let me know, how you did it. I am using Pager tag lib from JSPTags as well and i used collection object to iterate through. But i have some problems. I am wondeinf if you can help me with this
    Thanks
    Vik

  • How to do paging in a jsp and how to load data to specific pages

    I want to show 10 rows of data in a one page and remain in other pages. How to do it and let me know how to use tags inside display:table.Because I'm using a display:table tag to show data. Also I have already add requestURI attribute and map it inside struts-config.xml file with the neede .jsp to be loaded. But it didnt work as I want. Please help me.
    But the fact is sinse I'm getting data from a database and showing them using display:table tag I cannot understand where to put those offset like tags. Also I dont have the neccesary .tld. I will add here my code inside jsp file.Im working on struts framework and my ide is myeclipse.
    <display:table border = "0" width="100%" scope="session"  pagesize="15" offset="15" name="recievedReportQueues" styleClass="table_report" requestURI="receivingSmsReportPaging.do">
                          <display:column  property="id" title="Id"  align="center" href="recSMSValueShow.do?showRec=showRecievedDetails" paramId="recievedSMSValueSid" paramProperty="id"  sort="true" width="10%"/>   
                               <display:column property="module" title="Module" width="10%" align="center" sort="list"/>
      <display:setProperty name="sort.behavior" value="list" />
                          <display:setProperty name="paging.banner.include_first_last" value="true" />
                          <display:setProperty name="table_report" value="true" />
                          </display:table>ecievedReportQueues is the list of objects I'm getting from the session and its set inside the action class.
    Please help me with a sample code.Im really in a hurry to do this.
    Thanx..

    I want to show 10 rows of data in a one page and
    remain in other pages. How to do ithttp://onesearch.sun.com/search/onesearch/index.jsp?qt=jsp+pagination&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums
    Make sure you calculate the pagination before you invoke the JSP.

Maybe you are looking for

  • Sending 2 different idoc

    Hi All, I have a scenario with BPM where i need to receive two different idoc.  In this when I trigger from SAP one by one IDOC1 and IDOC2 it is executing properly but in case if I use transaction WE14 it is getting stucked in the loop step in BPM an

  • Itunes does not start even after reinstall

    Hi Ituners, I have a 64 bit windows 7 PC. Itunes recently crashed. When I tried to run it, my PC would freeze up and I would have to reboot it. I followed the directions from the apple forum on doing a complete unistall. When I went in to uninstall t

  • Infobus data form wizard returning ORA-03115

    Hi, I was trying to create a single table data form using (JBuilder2 )infobus data form wizard and during the step 3 (select database objects)i got following error: >> ORA-03115 Unsupported network data taype or representation java.sql.SQLException <

  • Change Colour of PopUp Lov

    I have the following code for a popup lov select a,b from select '1' res, htf.escape_sc(su.sukey) a, htf.escape_sc(su.sukey) b from udm_su su, udm_lde lde where su.ldeid = lde.ldeid and su.sukey in (select su_generic                  from vrp_cfg_gen

  • Concerning iphoto 11

    Since upgrading to iphoto 11 I,m having difficulty viewing my photos in edit mode. On the quick scan of info mode the photos appear sharp, however in edit mode the edges blur up making it very difficult to edit properly, What is the problem here?  I