Listing (Display) data page wise

hi experts,

I want to know hwo to write a code logic to dispaly a list of hundreds of records pages wise. May be per page only 10 records to be dispalyed. Also can click on any page NO and can go directly to that page.

===================
First  Previous  1   2   3   4   5   6 ......  Next  Last

Records.......1
.....
Records.......10

========================

My Code rite now is:
....
for(int i=0;i<events.length;i++)
{
    out.println(events[i].getName());
    out.println("<br>");
}
......
princehyderabadAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
siliconeagleConnect With a Mentor Commented:
replace with these:-
*the pagination.java just has the test vector taken out.
*you need to put the events[] array into a Vector and use the c:out tag to putput the data. see the comments.
-------------------Pagination.java----------------------------
package pagination;

import java.util.Iterator;
import java.util.Vector;
public class Pagination {
     private int page=0;
     private int messagesPerPage=50;
     private int maxPageList=10;
     public int getMaxPageList() {
          return maxPageList;
     }
     public void setMaxPageList(int maxPageList) {
          this.maxPageList = maxPageList;
     }
     public Vector getV() {
          return v;
     }
     public void setV(Vector v) {
          this.v = v;
     }
     Vector v;                                                                          
     public Pagination() { }
     public int getBase() {
          return this.page*this.messagesPerPage;
     }
     public Iterator getPageData() {
          try {
               if (v!=null) {
                    int start=this.page*this.messagesPerPage;
                    if (start>=v.size()) {page--;return  getPageData();}
                    if (start<0) {start=0;}
                    int finish=(this.page+1)*this.messagesPerPage;
                    if (finish>=v.size()) {finish=(v.size()>0)?v.size():0;}
                    return v.subList(start,finish).iterator();
               }
          } catch (RuntimeException e) {
               
          }
          return (new Vector()).iterator();
     }
     public int getMessagesPerPage() {
          return messagesPerPage;
     }
     public int getPage() {
          return page;
     }
     public void setMessagesPerPage(int i) {
          messagesPerPage = i;
     }
     public void setMessagesPerPage(String i) {
          try {     setMessagesPerPage(Integer.parseInt(i));}
          catch (NumberFormatException n) {     }
     }
     public void setPage(int i) {
          if (((i*this.messagesPerPage)<(v.size()-1))&&(i>=0)) {page = i;}
     }
     public void setPage(String i) {
          try {     setPage(Integer.parseInt(i));}
          catch (NumberFormatException n) {     }
     }
     public int getTotal() {
          return v.size();
     }
     public int getNumPages() {
          return (v.size()/this.messagesPerPage);
     }
     
     public void getNextPage() {
          setPage(getPage()+1);
     }
     public void getPrevPage() {
          setPage(getPage()-1);
     }
     
     public Iterator getPageList() {
          int start=start=page-maxPageList/2;
          if (start<0) {start=0;}
          int finish=page+maxPageList/2;
          if (finish>getNumPages()) {finish=getNumPages();}
          if ((start==0) && (finish<maxPageList)) {finish=maxPageList;}
          if ((finish==getNumPages()) && (start>getNumPages()-maxPageList)) {start=getNumPages()-maxPageList;}
          Vector pgs=new Vector();
          for (int i=start;i<finish;i++) {
               pgs.add(new Integer(i));
          }
          return pgs.iterator();
     }
     
}
--------------pages.jsp----------------------------------------
<%@ page import="java.util.*" %>
<jsp:useBean id="pager" scope="session" class="pagination.Pagination"/>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%
//// ADD you events array here.////////////
pager.setV(new Vector(Arrays.asList(events)));
/////////////////////////////////////
if (request.getParameter("next")!=null) {
pager.getNextPage();
}
else if (request.getParameter("prev")!=null) {
pager.getPrevPage();
}
else if (request.getParameter("page")!=null) {
pager.setPage(request.getParameter("page"));
}
else if (request.getParameter("msgpp")!=null) {
pager.setMessagesPerPage(request.getParameter("msgpp"));
}
%>
<a href="./pages.jsp?msgpp=10">10 per page</a>
<a href="./pages.jsp?msgpp=50">50 per page</a>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="./pages.jsp?prev=true">&lt;</a></td>
<td><c:forEach  items="${pager.pageList}" var="pg">
<a href="./pages.jsp?page=<c:out value="${pg}"/>"><c:out value="${pg}"/></a>&nbsp;</c:forEach></td>
<td><a href="./pages.jsp?next=true">&gt;</a></td>
<td>[page <c:out value="${pager.page}"/>]&nbsp;</td>
</tr>
<c:forEach items="${pager.pageData}" var="pg">
<%-- output you data here --%>
<tr><td ><c:out value="${pg.id}"/></td>
<td ><c:out value="${pg.severity}"/></td>
<td ><c:out value="${pg.dateCreated}"/></td>
<td ><c:out value="${pg.message}"/></td>
</tr>
</c:forEach>
</table>
----------------------------------------
0
 
petmagdyCommented:
like this:

Class pagination
{
//big array
String[] events;
int pagesize = 10;

0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
princehyderabadAuthor Commented:
Any help in sample code....
0
 
kiranhkCommented:
the links i posted has got all the sample code you want
0
 
petmagdyCommented:
sorry it seems i submit uncomplete

class Pagination
{

//big array (Vector object)
Vector events;
int pageSize = 10;
int currentPage=0;

 public void setThebigVector(Vector events)
{
   this.events = events;
}

 public Events[] getNextPage()
 {
  Vector onePage = Vector();
  //get the elements of the big vector from (currentPage * pageSize) to (  ( (currentPage+1)*pageSize) -1 )
  currentPage++
  return onePage.toArray();
 }
 
......
}


this is the idea
0
 
kiranhkCommented:
this means you need to get all the data at one shot from the DB and then keep calling your pagination class everytime. also u need to take care of checking which link numbered link has been clicked like if the current page is 3, the user might click anything after 3 or before 3.
The display tag and pager tag which i posted above will take care of all these for you.

0
 
princehyderabadAuthor Commented:
hi Kiranhk, I agree with U.
The links you send has what I wanted kind of stuff. I didnt know it will take soo many steps with soo many files to play around with. I'm kinda of new on JSP, so would U mind, helping me with step by step stuff to be done in suitation of my case code which is posted above. To make simple I'm displaying only Name's list. I hope it can get step wise instruction from U.

Regards,
Hyd
0
 
kiranhkCommented:
then whatever code petmagdy has given will be of better use to u

1) define the pagination bean in session scope.
2) retrieve all the data from DB and populate the Pagination bean
3) Then generate the 1,2,3 page number links
4) each click on the link u need to call the method of this class and retrieve the data and display it
0
 
princehyderabadAuthor Commented:
hi,

The code from above links, has make session=false, which I cant. Because my application session has to be true otherwise proper information would not be displayed if nagivate to other pages.

Anyother way to solve this ????
0
 
siliconeagleCommented:
here is a bean and jsp to display pages, you can do what you want with this

-------------------Pagination.java----------------------------
package pagination;

import java.util.Iterator;
import java.util.Vector;

/*
 *  (created at 27-Oct-2003 - 16:45:25 by 862438)
 * FolderList :
 */
/**
 * @author 862438
 */
public class Pagination {

      /**
       * Comment for <code>serialVersionUID</code>
       */
      private int page=0;
      private int messagesPerPage=50;
      private int maxPageList=10;
      /**
       * @return Returns the maxPageList.
       */
      public int getMaxPageList() {
            return maxPageList;
      }
      /**
       * @param maxPageList The maxPageList to set.
       */
      public void setMaxPageList(int maxPageList) {
            this.maxPageList = maxPageList;
      }
      /**
       * @return Returns the v.
       */
      public Vector getV() {
            return v;
      }
      /**
       * @param v The v to set.
       */
      public void setV(Vector v) {
            this.v = v;
      }
      Vector v;                                                                                          
      
      /**
       *  (created at 27-Oct-2003 - 17:50:45 by 862438)
       * @param folder
       */
      public Pagination() {
            v=new Vector();
            for (int i=0;i<1000;i++) {
                  v.add(new Integer(i));
            }
      }
      /**
       *  (created at 27-Oct-2003 - 16:45:25 by 862438)
       *
       */

      
      
      public int getBase() {
            return this.page*this.messagesPerPage;
      }
      
      public Iterator getPageData() {
            try {
                  if (v!=null) {
                        int start=this.page*this.messagesPerPage;
                        if (start>=v.size()) {page--;return  getPageData();}
                        if (start<0) {start=0;}
                        int finish=(this.page+1)*this.messagesPerPage;
                        if (finish>=v.size()) {finish=(v.size()>0)?v.size():0;}
                        return v.subList(start,finish).iterator();
                  }
            } catch (RuntimeException e) {
                  
            }
            return (new Vector()).iterator();
      }
      

      /**
       * @return
       */
      public int getMessagesPerPage() {
            return messagesPerPage;
      }

      /**
       * @return
       */
      public int getPage() {
            return page;
      }

      /**
       * @param i
       */
      public void setMessagesPerPage(int i) {
            messagesPerPage = i;
      }
      public void setMessagesPerPage(String i) {
            try {      setMessagesPerPage(Integer.parseInt(i));}
            catch (NumberFormatException n) {      }
      }
      /**
       * @param i
       */
      public void setPage(int i) {
            if (((i*this.messagesPerPage)<(v.size()-1))&&(i>=0)) {page = i;}
      }
      public void setPage(String i) {
            try {      setPage(Integer.parseInt(i));}
            catch (NumberFormatException n) {      }
      }
      public int getTotal() {
            return v.size();
      }
      
      
      public int getNumPages() {
            return (v.size()/this.messagesPerPage);
      }
      
      public void getNextPage() {
            setPage(getPage()+1);
      }
      public void getPrevPage() {
            setPage(getPage()-1);
      }
      
      public Iterator getPageList() {
            int start=start=page-maxPageList/2;
            if (start<0) {start=0;}
            int finish=page+maxPageList/2;
            if (finish>getNumPages()) {finish=getNumPages();}
            if ((start==0) && (finish<maxPageList)) {finish=maxPageList;}
            if ((finish==getNumPages()) && (start>getNumPages()-maxPageList)) {start=getNumPages()-maxPageList;}
            Vector pgs=new Vector();
            for (int i=start;i<finish;i++) {
                  pgs.add(new Integer(i));
            }
            return pgs.iterator();
      }
      
}

--------------pages.jsp----------------------------------------
<jsp:useBean id="pager" scope="session" class="pagination.Pagination"/>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%
if (request.getParameter("next")!=null) {
pager.getNextPage();
}
else if (request.getParameter("prev")!=null) {
pager.getPrevPage();
}
else if (request.getParameter("page")!=null) {
pager.setPage(request.getParameter("page"));
}
else if (request.getParameter("msgpp")!=null) {
pager.setMessagesPerPage(request.getParameter("msgpp"));
}
%>
<a href="./pages.jsp?msgpp=10">10 per page</a>
<a href="./pages.jsp?msgpp=50">50 per page</a>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="./pages.jsp?prev=true">&lt;</a></td>
<td><c:forEach  items="${pager.pageList}" var="pg">
<a href="./pages.jsp?page=<c:out value="${pg}"/>"><c:out value="${pg}"/></a>&nbsp;</c:forEach></td>
<td><a href="./pages.jsp?next=true">&gt;</a></td>
<td>[page <c:out value="${pager.page}"/>]&nbsp;</td>
</tr>
<c:forEach items="${pager.pageData}" var="pg">
<tr><td colspan="4"><c:out value="${pg}"/></td></tr>
</c:forEach>
</table>
0
 
princehyderabadAuthor Commented:
HI,  this is the 1st error.

Error: Failed to load or instantiate TagExtraInfo class: com.jsptags.navigation.pager.PagerTagExtraInfo

Also can u tell me where should I paste ur jsp code.
Shall I paste in between the for loop of my above code(Question) after getName();

Regards,
Hyd
0
 
kiranhkCommented:
no, u need to take out all your code and replace the code siliconeagle has given your. better still make it as a new jsp and then put all the code over there.

That error u r getting becoz u might be having the www.Jsptags.com pager tag. u need to have the jar file in the lib folder of ur web application.
but before debugging that u can try out what siliconeagle has given.
0
 
princehyderabadAuthor Commented:
hi kiranhk,
Yes I did what you said with New files. But yes seems like I'm missing c.tld file in web-inf folder. Siliconeagle has nto given any such file.

0
 
kiranhkCommented:
ok, this requires the tags from jstl. download the jstl library

http://cvs.apache.org/builds/jakarta-taglibs/nightly/

put all the jar files into the lib folder, add the tld files into WEB-INF folder and then in your web.xml you need to add the .tld
0
 
princehyderabadAuthor Commented:
Thanks for helping Kiranhk, yes I updated jar files now this is error.

Error"/JSP/Pag.jsp(22,4) No tag "forEach" defined in tag library imported with prefix "c"

0
 
kiranhkCommented:
ok, check out in c.tld whether forEach is there or not. if not search where forEach tag is there, then include that tld in the web.xml also
0
 
princehyderabadAuthor Commented:
Okay Kiranhk, now I need ur help. I got this code from other site. Its working fine. Now I'm confused hwo to merge with my code in order to make my application run like what I want 10 rows per page.

============This is printing 1 - 100, with 10 numbers page page=======
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>

<pg:pager url="http://www.altavista.com/cgi-bin/query" maxIndexPages="20"
             export="currentPageNumber=pageNumber">
  <pg:param name="pg"/>
  <pg:param name="q"/>

  <ex:searchresults>
<% for(int i=0;i<100;i++) {%>
    <pg:item>
      <%=i%>
    </pg:item>
      <% } %>
  </ex:searchresults>

  <pg:index>
    <font face=Helvetica size=-1>Result Pages:
    <pg:prev>&nbsp;<a href="<%= pageUrl %>">[&lt;&lt; Prev]</a></pg:prev>
    <pg:pages><%
      if (pageNumber.intValue() < 10) {
        %>&nbsp;<%
      }
      if (pageNumber == currentPageNumber) {
        %><b><%= pageNumber %></b><%
      } else {
        %><a href="<%= pageUrl %>"><%= pageNumber %></a><%
      }
    %>
    </pg:pages>
    <pg:next>&nbsp;<a href="<%= pageUrl %>">[Next &gt;&gt;]</a></pg:next>
    <br></font>
  </pg:index>
</pg:pager>
=================================================

This is my code to embed the above code, hope u can help me out.

for(int i=0;i<events.length;i++)
          {    
         
              <tr>
            <td ><%=events[i].getId()%></td>
            <td ><%=events[i].getDateCreated()%></td>
            <td ><%=events[i].getMessage()%></td>
          </tr>
    }
0
 
siliconeagleCommented:
this version is about 6 months old, so if you already have these libs (jar files) then DONT REPLACE THEM, as you might burn some other code on you site. this code should work with the most recent standard JSTL anyway.

here are the files if you can't find them at jakarta:-
http://www.robmunro.net/jstl/c.tld (Goes in WEB-INF)
http://www.robmunro.net/jstl/standard.jar (Goes in WEB-INF/lib)
http://www.robmunro.net/jstl/jstl.jar (Goes in WEB-INF/lib)
and
http://www.robmunro.net/jstl/jstl-reference-2004.pdf 
which is just a primer to help with the JSTL c tags

to configure the taglib add this to the bottom of your WEB-INF/web.xml
 <taglib>
  <taglib-uri>/WEB-INF/c</taglib-uri>
  <taglib-location>/WEB-INF/c.tld</taglib-location>
 </taglib>

they will be deleted in 48 hours, for security reasons.

hope this helps.


0
 
princehyderabadAuthor Commented:
Error: Pag1.jsp(22,4) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
After doing ur above side stuff.
0
 
siliconeagleCommented:
what server (and version) are you using?  
0
 
princehyderabadAuthor Commented:
Tomact 5.0
0
 
siliconeagleCommented:
is it the same as pages.jsp - can you post you code? for Pag1.jsp
0
 
siliconeagleCommented:
looks like you might have used a JSP expression (<%= %>) in the forEach tag.
0
 
siliconeagleCommented:
only EL expressions are allowed ${}
0
 
princehyderabadAuthor Commented:
Its same code what you have provided in pages.jsp above.
A - Z same code.
0
 
siliconeagleCommented:
can you send you web.xml?
0
 
princehyderabadAuthor Commented:
...
<taglib>
    <taglib-uri>http://paginationtag.miin.com</taglib-uri>
    <taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
...


Error now:  /jsp/Pag1.jsp(22,4) No tag "forEach" defined in tag library imported with prefix "c"
0
 
kiranhkCommented:
can you post your full web.xml and also list the contents of WEB-INF and lib Folders
0
 
princehyderabadAuthor Commented:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"  version="2.4">
  <taglib>
    <taglib-uri>http://jsptags.com/tags/navigation/pager</taglib-uri>
    <taglib-location>/WEB-INF/pager-taglib.tld</taglib-location>
  </taglib>
      <servlet>
              <servlet-name>Hello</servlet-name>
              <servlet-class>com.mario.servlet.HelloServlet</servlet-class>
      </servlet>

            
            
        <error-page>
                <exception-type>javax.ServletException</exception-type>
              <location>/error/commonerror.jsp</location>
      </error-page>
               <error-code>500</error-code>
        <location>/error/commonerror.jsp</location>
      </error-page>

      
        
        
<security-constraint>
        <web-resource-collection>
                <web-resource-name>MyFirst</web-resource-name>
                <description> accessible by authenticated users of the tomcat role</description>
                <url-pattern>/*</url-pattern>
                <http-method>GET</http-method>
                <http-method>POST</http-method>
                <http-method>PUT</http-method>
                <http-method>DELETE</http-method>
        </web-resource-collection>
        <auth-constraint>
                <description>These roles are allowed access</description>
                <role-name>tomcat</role-name>
                <role-name>Administrator</role-name>                
        </auth-constraint>
</security-constraint>

<login-config>
        <auth-method>FORM</auth-method>
        <realm-name>MyFirst Protected Area</realm-name>
        <form-login-config>
                <form-login-page>/login.jsp</form-login-page>
                <form-error-page>/autherr.html</form-error-page>
        </form-login-config>
</login-config>
<security-role>
        <description>Only role below is allowed to access this web application</description>
        <role-name>tomcat</role-name>
        <role-name>Administrator</role-name>
       <role-name>Read Only</role-name>
       
</security-role>
<taglib>
    <taglib-uri>http://paginationtag.miin.com</taglib-uri>
    <taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
       
</web-app>

WEB-INF:
  c.tld
 web.xml
 <lib>
     - standard.jar
     -jstl.jar
    -l0g4j-128.jar
   -activation.jar
  -pager-src.jar
  -pager-taglib.jar
  -xerces.jar
0
 
siliconeagleCommented:
no it has to be left the way it was, i.e.
<taglib>
  <taglib-uri>/WEB-INF/c</taglib-uri>
  <taglib-location>/WEB-INF/c.tld</taglib-location>
 </taglib>
i have modified the tld file try replacing it and restart your server:-
http://www.robmunro.net/jstl/c.tld
0
 
princehyderabadAuthor Commented:
I did now this is error:
Pag1.jsp(23,26) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
0
 
kiranhkCommented:
you can download the jstl tag library from this and add an entry into the web.xml after placing all the tld in WEB-INF folder, also place all the jars into the lib directory.


<taglib>
  <taglib-uri>/jstlc</taglib-uri>
  <taglib-location>/WEB-INF/c.tld</taglib-location>
 </taglib>


http://cvs.apache.org/builds/jakarta-taglibs/nightly/projects/standard/
0
 
princehyderabadAuthor Commented:
Okay Guys, it worked now !!
Thanks to you both.

But now you have to help me out to put my data into it...My data records code printed in this way... Let me know where to insert below code in Pag1.jsp ?

<%       for(int i=0;i<events.length;i++)
          {
          <tr>
            <td class="cellBGpista"><%=events[i].getId()%></td>
            <td class="cellBGpista"><%=events[i].getSeverity()%></td>
            <td class="cellBGpista"><%=events[i].getDateCreated()%></td>
            <td class="cellBGpista"><%=events[i].getMessage()%></td>
          </tr>
<%  } %>
0
 
kiranhkCommented:
<c:forEach  items="${events}" var="event">

        <td class="cellBGpista"><c:out value="${event.id}"/></td>
          <td class="cellBGpista"><c:out value="${event.severity}"/></td>
          <td class="cellBGpista"><c:out value="${event.dateCreated}"/></td>
          <td class="cellBGpista"><c:out value="${event.message}"/></td>
</c:forEach>
0
 
princehyderabadAuthor Commented:
Error: An error occurred while getting property "pageList" from an instance of class com.my.servlet.Pagination
0
 
siliconeagleCommented:
you probably havent set the event into the vector, see this line
//// ADD you events array here.////////////
pager.setV(new Vector(Arrays.asList(events)));
/////////////////////////////////////

cant help much more sorry.
0
 
princehyderabadAuthor Commented:
*you need to put the events[] array into a Vector and use the c:out tag to putput the data. see the comments.

---
//// ADD you events array here.////////////
pager.setV(new Vector(Arrays.asList(events)));
/////////////////////////////////////
---

This is my Arrays code, plz tell me how to replace in the above code, then I'm all set to run it.
   AzEvent[] events = null;
   events = (AzEvent[])request.getAttribute(LIST);

Thanks in advance.

Regards,
Hyd
0
 
kiranhkConnect With a Mentor Commented:
<%@ page import="java.util.*" %>
<jsp:useBean id="pager" scope="session" class="pagination.Pagination"/>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%
AzEvent[] events = null;
events = (AzEvent[])request.getAttribute(LIST);
pager.setV(new Vector(Arrays.asList(events)));

if (request.getParameter("next")!=null) {
pager.getNextPage();
}
else if (request.getParameter("prev")!=null) {
pager.getPrevPage();
}
else if (request.getParameter("page")!=null) {
pager.setPage(request.getParameter("page"));
}
else if (request.getParameter("msgpp")!=null) {
pager.setMessagesPerPage(request.getParameter("msgpp"));
}
%>
<a href="./pages.jsp?msgpp=10">10 per page</a>
<a href="./pages.jsp?msgpp=50">50 per page</a>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="./pages.jsp?prev=true">&lt;</a></td>
<td><c:forEach  items="${pager.pageList}" var="pg">
<a href="./pages.jsp?page=<c:out value="${pg}"/>"><c:out value="${pg}"/></a>&nbsp;</c:forEach></td>
<td><a href="./pages.jsp?next=true">&gt;</a></td>
<td>[page <c:out value="${pager.page}"/>]&nbsp;</td>
</tr>
<c:forEach items="${pager.pageData}" var="pg">
<%-- output you data here --%>
<tr><td ><c:out value="${pg.id}"/></td>
<td ><c:out value="${pg.severity}"/></td>
<td ><c:out value="${pg.dateCreated}"/></td>
<td ><c:out value="${pg.message}"/></td>
</tr>
</c:forEach>
</table>
0
 
princehyderabadAuthor Commented:
Error: According to TLD or attribute directive in tag file, attribute value does not accept any expressions
0
 
kiranhkCommented:
post the full stacttrace
0
 
princehyderabadAuthor Commented:
for this line: pager.setV(new Vector(Arrays.asList(events)));

Errors:
cannot resolve symbol symbol  : class Vector
cannot resolve symbolsymbol  : class Arrays
0
 
princehyderabadAuthor Commented:
NOw is the code. Oops now I'm getting different Error. Plz check and see if anything wrong. Mean while I'll fix my Servlet error. And thx for helping.

<%@ page import="java.util.*" %>
<jsp:useBean id="pager" scope="session" class="pagination.Pagination"/>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg" %>
<%
AzEvent[] events = null;
events = (AzEvent[])request.getAttribute(LIST);
pager.setV(new Vector(Arrays.asList(events)));
 
if (request.getParameter("next")!=null) {
pager.getNextPage();
}
else if (request.getParameter("prev")!=null) {
pager.getPrevPage();
}
else if (request.getParameter("page")!=null) {
pager.setPage(request.getParameter("page"));
}
else if (request.getParameter("msgpp")!=null) {
pager.setMessagesPerPage(request.getParameter("msgpp"));
}
%>
<a href="./pages.jsp?msgpp=10">10 per page</a>
<a href="./pages.jsp?msgpp=50">50 per page</a>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="./pages.jsp?prev=true">&lt;</a></td>
<td><c:forEach  items="${pager.pageList}" var="pg">
<a href="./pages.jsp?page=<c:out value="${pg}"/>"><c:out value="${pg}"/></a>&nbsp;</c:forEach></td>
<td><a href="./pages.jsp?next=true">&gt;</a></td>
<td>[page <c:out value="${pager.page}"/>]&nbsp;</td>
</tr>
<c:forEach items="${pager.pageData}" var="pg">
<%-- output you data here --%>
<tr><td ><c:out value="${pg.id}"/></td>
<td ><c:out value="${pg.severity}"/></td>
<td ><c:out value="${pg.dateCreated}"/></td>
<td ><c:out value="${pg.message}"/></td>
</tr>
</c:forEach>
</table>
0
 
siliconeagleCommented:
get rid of this line:
<%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg" %>

also possibly LIST should be a string where does it comes from as its not declared here.
0
 
princehyderabadAuthor Commented:
org.apache.jasper.JasperException
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
                .....

This is the error:  Any Idea ?
0
 
siliconeagleCommented:
this is the wrong p[art of the exception there is a "root cause" part at the bottom of the page or it goes into the TOMCAT_HOME/logs directory under todays date.
0
 
princehyderabadAuthor Commented:
Okay guys, I think we are almost there, there are no errors, but the output page is blank and when I saw the source I found something here.....
I think this need to be fixed in proper array style then we are all set.
<c:forEach  items="java.util.AbstractList$Itr@1c160cb" var="pg"> and <c:forEach items="java.util.SubList$1@b9b67b" var="pg">

Regards,
Hyd

==================Output Code===================================================
<tr>
<td><a href="./pages.jsp?prev=true">&lt;</a></td>
<td>
<c:forEach  items="java.util.AbstractList$Itr@1c160cb" var="pg">  [??????????????????????????????????????????]
<a href="./pages.jsp?page=<c:out value=""/>"><c:out value=""/></a>&nbsp;</c:forEach></td>
<td><a href="./pages.jsp?next=true">&gt;</a></td>
<td>[page <c:out value="0"/>]&nbsp;</td>
</tr>
<c:forEach items="java.util.SubList$1@b9b67b" var="pg"> [??????????????????????????????????????????]
<tr><td ><c:out value=""/></td>
<td ><c:out value=""/></td>
<td ><c:out value=""/></td>
<td ><c:out value=""/></td>
</tr>
</c:forEach>
0
 
kiranhkCommented:
can you post the new jsp file which u have modified now to get this output.

0
 
princehyderabadAuthor Commented:
It worked finally. Good work guys.

Thanks a lot siliconeagle
Thanks a lot  kiranhk

Regards,
Hyd
0
 
kiranhkCommented:
UR WC
Glad to hear that it worked.

0
 
siliconeagleCommented:
glad you got there, have fun.
0
 
princehyderabadAuthor Commented:
Need a small help again. The above code displays all the events for all Servers. I want to display particular Server events on some page. This was the code worked without using jstl ie <c:if test... ????

========================My code ======================

<%
String ipa = request.getParamater("ServerName")
AzEvent[] events = null;
events = (AzEvent[])request.getAttribute(LIST);

for(int i=0;i<events.length;i++)
          {
          if ( ipa.equals(events[i].getServer().getIpAddress()) )
                { %>
          <tr>
            <td><%=events[i].getId()%></td>
            <td><%=events[i].getSeverity()%></td>
            <td><%=events[i].getDateCreated()%></td>
            <td><%=events[i].getMessage()%></td>
          </tr>
<% }       } %>
=====================================

How do u write the above code specialy the "if" condition using <c:if test ...

Using our accepted code above I tried like this but ddont worked...
<c:forEach items="${pager.pageData}" var="pg">
<% String s =events.getResource().getIpAddress(); %>
      <c:if test='${pg.id ==param.s }'>

Regards,'Hyd
0
 
siliconeagleCommented:
<c:if test="${pg.id ==param.s }"> </c:if> use double quotes in taglibs. its not like javascript quotes matter.

if you are unsure if a value then print it out using <c:out value="${param.s}"/> to check it.  i usually use <c:out value="${param['s']}"/> this gets a request parameter (if url?s=xxx then this gives xxx)

 i think you just want <c:out value="${s}"/> or  <c:if test="${pg.id==s }">...</c:if>

try to refer to the reference PDF :-
http://www.robmunro.net/jstl/jstl-reference-2004.pdf

all the info is in there, try playing around with the tags, save it on you disk as it will be deleted soon.
0
 
princehyderabadAuthor Commented:
I tried this:
<% String s =events.getServer().getIpAddress(); %>
<c:out value="${param.s}"/>

Error: cannot resolve symbol symbol  : method getServer ()

I'm messing somewhere with []...
this worked fine for me if ( ipa.equals(events[i].getServer().getIpAddress()) )
If u see my today's code above U'll understand...

Regards
0
 
siliconeagleCommented:
String s =events[i].getServer().getIpAddress();

events is an ARRAY of event objects, you need to refer to a particular event object (events[i] accesses the ith event object in the array) to acces the methods of the event object.
0
 
princehyderabadAuthor Commented:
Yes, thats where I'm not getting.

Where is the 'i' define here....
<c:forEach items="${pager.pageData}" var="pg">
<% String s =events.getResource().getIpAddress(); %>

In my code 'i' is define here..
AzEvent[] events = null;
events = (AzEvent[])request.getAttribute(LIST);

for(int i=0;i<events.length;i++)
          {
          if ( ipa.equals(events[i].getServer().getIpAddress()) )
               { %>
         <tr>
          <td><%=events[i].getId()%></td>
          <td><%=events[i].getSeverity()%></td>
          <td><%=events[i].getDateCreated()%></td>
          <td><%=events[i].getMessage()%></td>
         </tr>
<% }       } %>
0
 
siliconeagleCommented:
events[i]=pg
pg is the variable for each iteration of the loop
so i think what you need is
<c:if test="${ipa==pg.server }"> ... </c:if>

i think it time to start a new thread if you have more questions.
0
 
princehyderabadAuthor Commented:
Here is the new thread I created.
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21196189.html

The error I'm getting is with ur above code:

Error: The function server must be used with a prefix when a default namespace is not specified

Also note, U'll get IP only thru this way "getServer().getIpAddress()" as u can see above in my jSP code.

Regards,
Hyd


0
All Courses

From novice to tech pro — start learning today.