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>

Similar Messages

  • 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

  • Best way to create, modify, XML with JSP ?  HELP

    Hi friends,
    As i am new to XML,
    I know there are two APIs used for XML processing, i want to know as a begineer level, which API
    is easy and good to implement XML with JSP.
    1) SAX
    2) DOM
    i want to make a log file in XML, so on web page it will be displayed on HTML form through XSL.
    Since there is good tutorial on http://www.w3schools.com/dom
    but i think its HTML dom
    I want XML procession through JAVA CODE , what should i use ? and give some good tutorials on XML DOM
    that is used with JAVA / JSP.
    HELP.
    Edited by: Ghanshyam on Sep 19, 2007 3:24 PM

    Well what i think is you gonna checkout with your requirements before implementing any of the popular XML parsing mechnisms.
    If you are intrested in faster processing @sacrifising a gud amount of your Memory,DOM is the one which you are looking for.
    If you are instrested in Managing your memory and but if you are ok with sacrifising speed SAX is the best solution.it works on what is called a push technology.
    and if you think either way you might have to look towards a pull parser which is StAX (Streaming API for XML Parsing)
    it'd be a gr8 idea if you can go through the below article which explians about each of the parsing mechanisms
    http://www.stylusstudio.com/xml/parser.html#*
    coming back to helpful resources as far java is concern checkout the below link which might be of some help.
    and the main thing is that all of these parser there is a defined specification you might find implementations of different vendors on this.
    eg:Sun Provides one with JDK itself,same as IBM provides one,oracle does the same & so on...
    your first task would be to focus on one such implementation which can cater your requirements.
    DOM:*
    Basic Parsing Objects / Interfaces Involved while DOM parsing:
    http://www.w3.org/TR/DOM-Level-2-Core/java-binding.html
    Breif Overview & few important API details:
    http://www.developerlife.com/domintro/default.htm
    Simple Example:
    http://www.brics.dk/~amoeller/XML/programming/domexample.html
    Others:
    http://www.roseindia.net/xml/dom/
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM.html#wp79994
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/1_read.html
    SAX:*
    http://www.javacommerce.com/displaypage.jsp?name=saxparser1.sql&id=18232
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/index.htm
    http://java.sun.com/developer/Books/xmljava/ch03.pdf
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPSAX.html#wp69937
    http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=6
    StAX:*
    http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP2.html
    http://javaboutique.internet.com/tutorials/stax/
    http://today.java.net/pub/a/today/2006/07/20/introduction-to-stax.html
    Hope this might be of some help :)
    REGARDS,
    RaHuL
    http://weblogs.java.net/blog/spericas/archive/2006/04/sun_stax_parser.html

  • 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.

  • Char into balise jsp:scriptlet in jsp with xml syntax

    hello,
    i met a trouble with coding jsp with xml syntax,
    i use wsad to develop the jsp, and it's not allowed to put characters < or > into the balise scriptlet
    for example i cant do a loop (as i did easily with html syntax <% %> ) :
    this his the header of my jsp:
    <jsp:directive.page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
    <jsp:text>
    <![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
    </jsp:text>
    <jsp:text>
    <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> ]]>
    </jsp:text>
    and the code which dont work:
    <jsp:scriptlet>
    for (int i=0;i<10;i++){
    System.out.println(i);
    </jsp:scriptlet>
    i get a compilation error, did someone could help me to code dynamic content jsp ?
    ps: excuse me for my english.

    I don't use xml, so I may be way off the wall, but did you try using the CDATA sections again?
    <jsp:scriptlet>
    <![CDATA[
    for (int i=0;i<10;i++){
    System.out.println(i);
    ]]>
    </jsp:scriptlet>

  • Passing variables between data tag and JSP-scriptlets

    Hi,
    There were some questions about this issue. However, the answers were not satisfactory.
    I would like to assign the value returned from data tag to a variable in JSP-scriptlets as follows:
    <%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
    <br>
    <jbo:ApplicationModule id="isae.OPKv1.OPKv1Module" configname="isae.OPKv1.OPKv1Module.OPKv1ModuleLocal" username="t1" password="t1"/>
    <br>
    <!-- a record is selected -->
    <jbo:DataSource id="ds" appid="isae.OPKv1.OPKv1Module" viewobject="AePk100View" whereclause=" <%= ic %> " />
    <br>
    <jbo:Row id="privRow" action="CURRENT" datasource="ds">
    <%
    String privName = (String) privRow.getAttribute("ArBau325"); // this is the suggestion of William Dwight (Jan 21, 2001 this forum)
    %>
    </jbo:Row>
    This code did not work. I have obtained an error :
    java.lang.ClassCastExeption
    Any help would be greatly appreciated.
    Thanks

    The value return by the getAtribute might not be of type String. If you want to return a String value you need to convert the value using the toString method as follow:
    <jbo:Row id="privRow" action="CURRENT" datasource="ds"/>
    <%
    String privName = "";
    Object obj = privRow.getAttribute("ArBau325");
    if (obj != null)
    privName = obj.toString();
    %>
    Also note that you do not need to put the scriplet code inside the body of the row tag.
    Charles.

  • 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

  • Looking up a EJB 3.0 Session Bean in JSP Scriptlet

    Hello There,
    Somebody please enlighten me. I have a bean named
    a.b.MyBeanextending local interface
    a.b.MyLocalNow I want to use this bean in a JSP (Maybe just for fun, but the point is I am not using resource injection).
    So the question is, What is the default JNDI name of the session bean with only a local interface, which I can use to look-it-up in jsp scriptlet code.
    Cheers. Am trying for last hour, nothings turned up
    Bye

    It's the classname under the initial context or a.b.MyLocal in your case.
         <% MyLocal intf = null;
              try {
                   InitialContext context = new InitialContext();
                   intf = (MyLocal) context.lookup(MyLocal.class.getName());
              } catch (Exception ex) {
                   System.err.println("Error looking up MyLocal: " + ex.getMessage());
              } %>

  • Error while using jsp scriptlet or expression with JSPDynpage default jsp

    Hi everyone,
    I am getting the following error while trying to use any kind of jsp scriptlet or expression within the default jsp page that is created with JSPDynpage application:
    Portal Runtime Error
    An exception occurred while processing a request for :
    iView : Navroz_JSPDynPage_JCo_BAPI_FLCUST.FlightCustJSP
    Component Name : Navroz_JSPDynPage_JCo_BAPI_FLCUST.FlightCustJSP
    Error occurs during the rendering of jsp component.
    Exception id: 08:50_05/10/06_0032_17543050
    See the details for the exception ID in the log file
    For example if I try to use even simple syntax like:
    <% if(true) { %>
    display htmlb tableviewcomponent
    <% } %>
    or
    <hbj:tableView
         id="myTableView"
         model="flightCustomer.model"
         design="ALTERNATING"
         headerVisible="true"
         footerVisible="true"
         fillUpEmptyRows="true"
         navigationMode="BYLINE"
         selectionMode="SINGLESELECT"
         headerText="Flight Customer List"
         onNavigate="Navigate"
         visibleFirstRow="<%=flightCustomer.getVisibleFirstRow()%>"
         visibleRowCount="5"
         rowCount="16"
         width="500 px"
         />
    here also the <%=flightCustomer.getVisibleFirstRow()%> line gives the above mentioned error. If I remove such scriptlets or expression then it works fine.
    What could be the problem. Are jsp scriptlets or expressions incompatible with portal applications?

    hi Navroz,
    check this
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/90e8e837-cc15-2a10-8db1-a87e2d29e9c9
    Re: Defining HTMLB tags in jsp file of JspDynPage component
    Re: JSPDynPage does not work in EP6.0
    bit more
    JspDynPage with Client Side Eventing and Database
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b3c1af90-0201-0010-c0ac-c8d802d264f0
    let me know u need any further info
    bvr

  • Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

    I have
    <c:set var="myVar" value="..." />
    I need to replace single quotes and double quotes to be escaped because I pass them into javascript functions and set them as ID for div sections
    ... onclick ="func('${myVar}')" ..
    <div id="${myVar}">
    but if the string contains ' single quotes it messes up the javascript or double quotes messes up the ID portion of the HTML tag
    I know there is the JSTL function fn but I can't figure out how to do it properly in JSTL
    <c:set var="myVar"
    value="${fn:replace(myVar, "'", "\"")"/>
    But that gets tricky since the value portion is enclosed in quotes
    So I was thinking of using a Scriptlet part instead.

A: Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

escaping quotes within quotes within quotes.... ARGH!
Recipe for a headache if ever there was one.
However you must be strong and resist the temptations of the dark side (Scriptlet code)
My suggestion for cleaning this up - write your own static function for escaping javascript strings.
public static String escapeJavascriptString(String s){
  return .......
}Then define the function in a tld:
<function>
    <description>
      Escapes a string for javascript purposes
    </description>
    <name>escapeJavascript</name>
    <function-class>com.mypackage.ELFunctions</function-class>
    <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature>
    <example>
      <c:out value="${myfunc:escapeJavascript(name)}">
    </example>
  </function>Cheers,
evnafets

escaping quotes within quotes within quotes.... ARGH!
Recipe for a headache if ever there was one.
However you must be strong and resist the temptations of the dark side (Scriptlet code)
My suggestion for cleaning this up - write your own static function for escaping javascript strings.
public static String escapeJavascriptString(String s){
  return .......
}Then define the function in a tld:
<function>
    <description>
      Escapes a string for javascript purposes
    </description>
    <name>escapeJavascript</name>
    <function-class>com.mypackage.ELFunctions</function-class>
    <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature>
    <example>
      <c:out value="${myfunc:escapeJavascript(name)}">
    </example>
  </function>Cheers,
evnafets

  • How to use jsp:scriptlet in site template

    hi all,
    I want to use <jsp:scriptlet> in site template, but jdev showed me an error msg when I put <jsp:scriptlet> in site template:
    scriptlet can not work properly with OJSP, I checked the forums, one possible solution is to encapsulate java code in jsp taglib, but I dislike this solution.
    Is there a way to disable OJSP? or any solution to use java code in site template?
    Best regards

    I believe the official word is if you are trying to use java code in a scriptlet in your site template then you are doing something wrong.
    The goal is to keep java code separate from the template and pages. Any logic should go to your supporting serviece objects and all of your front-end work should be accomplished using available or custom tags.
    Can you describe what you are trying to accomplish with this java code in your template?

  • Class and Methods in JSP Scriptlets?

    Is it possible to declare functions or classes in a JSP scriptlets? If so, what would be the proper syntax in doing so?

    Use the exclamation mark.
    <%!
        public void doSomething() {
            // Implement.
    %>Although rather use servlets or beans for business logic and use JSP for display only.

  • Error:the prefix "jsp"  for element "jsp:scriptlet" is not bound

    i got this error:
    the prefix "jsp"  for element "jsp:scriptlet" is not bound.how can i remove this error.

    Add this to the jsp:root tag
    xmlns:jsp="http://java.sun.com/JSP/Page"
    How did it get removed from your JSP?
    (assuming you are using Sun Java Studio Creator)

  • Maybe you are looking for

    • 8while generating reports is there any standard way of fectching

      8.while generating reports is there any standard way of fectching data.i.e u have take matnr from mara not from makt.etc any tips please.

    • ACH Addenda record

      Hi All, We are using PMW with an ACH CCD format to send the ACH files to our Bank. But certain vendors require us to send ADDENDA record as given below for e.g.  in the ACH payments 705ISA00NV 00NV ZZNV ZZNV 09100615300010000001 Can we enter this inf

    • Smartforms.generating fm

      Hi experts, I am getting error when fm SSF_FUNCTION_MODULE_NAME is executing.....i am getting error as "Error during generation of form ZQM_HANDSLIP".....it is working properly in devlopment,but in production i am getting this error. the code is as f

    • Iphone stopped working

      I updated my iphone 4 software and connected to itunes so the update could be completed. When the dowload ended in itunes a message appeared that the iphone wasn't eligible for the dowload and the iphone started turning on and off. Then the screen tu

    • Making buttons in photoshop

      There is a way to create custom buttons in Photoshop that exibit the 3 states that a button has: 1. Not Selected 2. Selected 3. Activated I believe that 3 layers need to be created, one for each state??? If so Just How do you Specify Which layer is w