Link to home
Start Free TrialLog in
Avatar of foongkim
foongkim

asked on

Multipage Layout Data

Hi, this is the sample coding and I hope anyone can teach me how to do multipages listing if my data is very big but I don't want to show them all in one pages. I want it to be multi pages. Thank you.

<%@ page language="java"
    import="java.sql.*, java.io.*, java.util.*, com.wrox.cars.*"
%>

<jsp:useBean id="book" class="com.wrox.cars.Books" />

<html>
  <head>
      <title> Testing For Data Access </title>
  </head>

<body>
  <h1> List Of Data From PFLIB/JAPF10  </h1>

<table border ="1">

        <tr>
           <td><b>Customer Name </b></td>
        </tr>

        <%
           book.connect();
           ResultSet rs = book.viewBooks();
           while (rs.next()) {
        %>

        <tr>
           <td><%= rs.getString("TA1021") %></td>
        </tr>

        <%
         }
        %>
</table>
<% book.disconnect(); %>
</body>
</html>


I am using JavaBeans to do the connection and sql query. Please teach how to do multipages.

TQ
Avatar of cheekycj
cheekycj
Flag of United States of America image

Ok.. I can give you simple pseudocode.

Ideally you want to use a taglib like struts or some other one to do this.. but you can try this until then:

<%@ page language="java"
   import="java.sql.*, java.io.*, java.util.*, com.wrox.cars.*"
%>
<% int maxDisplay = 50;
   String sr = request.getParameter("sr");
   int startRow = 0;
   try {
     if (startRow != null)
      startRow = Integer.parseInt(sr);
   } catch (NumberFormatException nfe) {
       startRow = 0;
     }

<jsp:useBean id="book" class="com.wrox.cars.Books" />

<html>
 <head>
     <title> Testing For Data Access </title>
 </head>

<body>
 <h1> List Of Data From PFLIB/JAPF10  </h1>

<table border ="1">

       <tr>
          <td><b>Customer Name </b></td>
       </tr>

       <%
          book.connect();
          ResultSet rs = book.viewBooks();
          int numDisplayed = 0;
          int currentCount = 0;
          while (rs.next() && numDisplayed < maxDisplay) {
            if (currentCount < (startRow + maxDisplay)) {
            numDisplayed++;
       %>

       <tr>
          <td><%= rs.getString("TA1021") %></td>
       </tr>

       <%
           }
           currentCount++;
        }
       %>
</table>
<% book.disconnect(); %>
</body>
</html>
Avatar of foongkim
foongkim

ASKER

Yes, since you touch about the taglib, I am in the middle of finding answer of this vocab called "Taglib".

How can I use these easiest way to do my coding. If I am  not mistaken, I need to specified the URL of these taglib. Is it I have to create this taglib by my own or how?

Can share?
cheekyci, I have tried the psedocode, it's will displayed how many "maxDisplay" I specified inside the program but it's doesn't hold my data for the next pages.

I have definitely more than 50 lines data here, but can I initiated my system to hold my others data to be stored innext pages???
You can get taglibs from various sites.

the best one is:
http://jakarta.apache.org/taglibs/index.html

Struts is easy to use and would be your best bet.

CJ
Thank you very much......
But I am using JSP 1.0. Did it support tag Library?
I believe JSP 1.1 is when Taglib support was started.

CJ
Any strong documentation support you or did u tried before using JSP 1.0?

By the way, I just read some documentation regarding my multipages layout, anything to do with my database if I want to view my data in multiple pages? Or the code itself should add-in more code?

 
ASKER CERTIFIED SOLUTION
Avatar of sushifish
sushifish

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry guys.... for disapear almost a month.

the code that suchfish recomended is working. But I was wonering how abouht the next 50 records, 51, 52.... will be display??

I am not sure.. suchfish any comments?

can you post your completed code.. so we can examine it?

CJ
That's the only code I have.....

Totaly no idea.... I was wondering either the admin of the pages can share his/her code with us or not..

Ha....