How to done Next and Previous operations using(struts or jsp and servlets).

I have some problem with Next and Previous Operations in my application. I solve that problem by my own. But I need some more information to solve that problem.
In order to solve this problem, 1st i moved all the Dara Base records into one collection.And I set that collection Object in Session scope in Servlet file.And i dispatch the request to one jsp(Show.jsp) . The code of that is given bellow.
<%@page language="java"%>
<%@page import="java.util.*"%>
<%@page import="home.servlet.beans.*"%>
<%!
     public static int no=0;
%>
<html>
     <body>          
               <%
                    String s=request.getParameter("nam");
                    if(s==null)
                         s="some";
                    ArrayList a=(ArrayList)session.getAttribute("tv");
                    if(!s.equals("pre"))
                         int i=no;
                         %>
                         <table border=1>
               <tr>
                    <th>DEPTNO</th>
                    <th>DNAME</th>
                    <th>LOC</th>
               </tr>
               <%
                    if((no+1)<a.size())
                    for(i=no;i<(no+2);i++)
                         SelectBean sb=(SelectBean)a.get(i);
                         %>
                         <tr>
                              <td><%=sb.getDeptno()%></td>
                              <td><%=sb.getDname()%></td>
                              <td><%=sb.getLoc()%></td>
                         </tr>
                         <%
                         no=no+2;
                    else
                         if(i<a.size())
                         for(i=no;i<a.size();i++)
                         SelectBean sb=(SelectBean)a.get(i);
                         %>
                         <tr>
                              <td><%=sb.getDeptno()%></td>
                              <td><%=sb.getDname()%></td>
                              <td><%=sb.getLoc()%></td>
                         </tr>
                         <%
                         else
                              out.println("<tr><td colspan='3'>There is no records to display</td></tr>");
                    else
                         %>
                         <table border=1>
               <tr>
                    <th>DEPTNO</th>
                    <th>DNAME</th>
                    <th>LOC</th>
               </tr>
               <%
                         if(no==a.size())
                              no=no-1;
                         int i=no;
                         for(i=no;i>(no-2);i--)
                              if(i==-1)
                                   break;
                              SelectBean sb=(SelectBean)a.get(i);
                         %>
                         <tr>
                              <td><%=sb.getDeptno()%></td>
                              <td><%=sb.getDname()%></td>
                              <td><%=sb.getLoc()%></td>
                         </tr>
                         <%                               
                         no=no-2;
                         if(no<0)
                              no=0;
               %>
               </table>
               <br>
               next
               previous
     </body>
</html>
If u have any other idea please reply to me. Please copy the above code and work with your application.

It's a classic paging feature.
And since it's a classic feature, you have most of the work already done for you, like JSP paging tags.
You just need to Google for "jsp tag paging" or something to that effect to get several useful links.

Similar Messages

  • Next page previous page using JDBC in JSP

    Hello,
    I wanted to know how the previous page and next page is developed when an user serches for a particular string in a web site.They are restricting the database to display only 10-25 rec per page and giving an option like next, when an user clicks next the next 10-25 rec are shown how is this done.
    Please e-mail me the source code if availabale to [email protected]
    Thanks in advance
    Anu
    null

    Hi Anu,
    visit technet.oracle.com site, go to sample section, in that choose JDBC section, here you will find example similar to your problem which you have describe below -
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Anu:
    Hello,
    I wanted to know how the previous page and next page is developed when an user serches for a particular string in a web site.They are restricting the database to display only 10-25 rec per page and giving an option like next, when an user clicks next the next 10-25 rec are shown how is this done.
    Please e-mail me the source code if availabale to [email protected]
    Thanks in advance
    Anu
    <HR></BLOCKQUOTE>
    null

  • How to list an array of objects using struts in jsp and ActionForm

    I am using the struts ActionForm and need to know how to display an Array of objects. I am assuming it would look like this in the ActionForm:
    private AddRmvParts addRmv[];
    But I am not sure how the getter and setter in the ActionForm should look. Should it be a Collection or an Iterator?
    I am thinking I need to use an iterator in the jsp page to display it.
    I am also wondering if the AddRmvParts class I have can be the same class that gets populated by the retrieval of data from the database. This class has 10 fields that need to display on the jsp page in 1 row and then multiple rows of these 10 fields.
    Thanks.

    Most probably the easiest way to make it accessible in your page is as a collection.
    ie
    public Collection getAddRmvParts()
    You can use the <logic:iterate> or a <c:forEach>(JSTL) tag to loop through the collection
    As long as the individual items in the collection provide get/set methods you can access them with the dot syntax:
    Example using JSTL:
    <c:forEach var="addRmvPart" items="${addRmvParts}">
      <c:out value="${addRmvPart.id} ${addRmvPart.name} ${addRmvPart.description}"/>
    </c:forEach>

  • How to make next and previous button function

    Hello
    Can anybody help me with how to achieve next and previous button function such as the one at www.bestbuy.com?
    I would appreciate any help or suggestion.
    Thank you!

    if you're not familiar with flash it might be easiest to place your initial "page" in frame 1, the 2nd (or next) page in frame 2, the 3rd/next page in frame 3 etc.
    place your previous and next buttons in their own layer that spans the main timeline (which will have as many frames as you have "pages").  give them instance names (say prevBtn and nextBtn).
    you can then use the following code placed in frame 1:
    var tl:MovieClip=this
    prevBtn.onRelease=function(){
    tl.prevFrame();
    nextBtn.onRelease=function(){
    tl.nextFrame();

  • How to connect "Next" and "Previous" ?

    Hi everyone,
    I am new in this with videoediting etc but I just managed to finish my first real videoproject and burned a DVD last night.
    My first Encore project crashed after 3 days but I could start a new project and finish that one within 4 hours. Great program.
    The DVD works fine except for1 thing:
    I could not figure out how to connect "Next" and "Previous" in my Submenu for choosing clips.
    So I just deleted these functions (!)
    Looking forward to next project but I would like to use these 2 functions!
    Thanks in advance!
    Great forums in Adobe with Great People!

    Thank you !
    I thought it was to go to Next clip and previous clip. Not very good thinking.....
    Now I understand!
    Thanks again!

  • How do I restore a previous operating system to my iMac

    How do I return to previous operating system.  I have 2007 Mac with upgraded 4 Gb and snow leopard and moved to Maverick and system does not have CPU handle oS 10.9. need to return to 10.7.
    Disk fr snow leopard will not load.

    OS X Mavericks: Revert to a previous OS X version

  • How to load data into html:select using Struts ?

    How to load data into <html:select> using Struts ?
    I can not load an array or collection (static or dynamic data) into drop down list control by <html:select /> Struts.
    please use:
    <html:select >
    <html:options />
    </html:select >
    Please help me. please detail it. thanks a lot.
    Message was edited by:
    tranminhman

    In order to load a collection or array of data you can use <html:select> with <html: options collection="" name=""/>
    here collection attribute refers to the Arraylist or Array of data and name is the name of the Form bean.
    Hope this helps...
    Chaitanya V

  • X6 : how to get next and previous controls working...

    Hi,
    May be i am missing how to do the same...but i can't get the the next video by pressing the next icon on the real player...i am viewing the video files from the gallery..Or the next and prev controls won't work..

    Hi,
    In that case it's too bad..

  • How to get next and previous page  in a Train Flow .

    Hi,
    For creating record I am using multi-step flow (train).
    I have three page and I want to navigate the page via multi-step flow (train).
    I followed the steps given in the Toolbox Tutorial of create purchase order and
    Locator Element: Page/Record Navigation in developer's guide.
    page1=/uttara/oracle/apps/uttaraimc/createcitizen/webui/PropertyCreatePG
    page2=/uttara/oracle/apps/uttaraimc/createcitizen/webui/HouseDetailsCreatePG"
    page3=/uttara/oracle/apps/uttaraimc/createcitizen/webui/EducationCreatePG"
    The page1 is navigated via 'Create' button in CitizenSearchPG
    Now on this Page1, when I clicks on the 'Next' button (to navigate to the next page in the same multi-step flow) I am getting following exception and its not navigating to page2.
    Error: Cannot Display Page
    You cannot complete this task because one of the following events caused a loss of page data:
    * You accessed this page using the browser's navigation buttons (the browser Back button, for example).
    * Your login session has expired.
    * A system failure has occurred.
    To proceed, please select the Home link at the top of the application page to return to the main menu. Then, access this page again using the application's navigation controls (menu, links, and so on) instead of using the browser's navigation controls like Back and Forward.
    Here is the code for CreateFooterCO,
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OANavigationBarBean navBean =
    (OANavigationBarBean)webBean.findChildRecursive("NavBar");
    if (navBean == null)
    MessageToken[] tokens = { new MessageToken("OBJECT_NAME", "NavBar") };
    throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", tokens);
    // Determine which page we're on so we can set the selected value. Each
    // time we navigate to and within the flow, the URL includes a parameter
    // telling us what page we're on.
    int step = Integer.parseInt(pageContext.getParameter("ccStep"));
    navBean.setValue(step);
    // Figure out whether the "Submit" button should be rendered or not;
    // this should appear only on the final page (Step 3).
    OASubmitButtonBean submitButton =
    (OASubmitButtonBean)webBean.findIndexedChildRecursive("Submit");
    if (submitButton == null)
    MessageToken[] tokens = { new MessageToken("OBJECT_NAME", "Submit") };
    throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", tokens);
    if (step != 3)
    submitButton.setRendered(false);
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    int currentStep = Integer.parseInt(pageContext.getParameter("ccStep"));
    // This button should only be displayed on the final page...
    if (pageContext.getParameter("Submit") != null)
    // Simply telling the transaction to commit will cause all the Entity Object validation
         // to fire.
    // Note that you must commit before asking WF for the next page, because
    // asking for the next page at this point will transition the WF to a
    // completed state, which means you won't be able to navigate back
    // if there are errors during the commit processing.
    am.invokeMethod("apply");
    TransactionUnitHelper.endTransactionUnit(pageContext, "citizenCreateTxn");
    // Don't forget to call this even on the last page so the activity associated with
    // this page completes and the Workflow transitions appropriately.
    String nextPage = OANavigation.getNextPage(pageContext);
    // For the final page, Workflow should be returning null -- and the user
    // can select the "Submit" button only on the last page. Something's
    // wrong.
    if (nextPage != null)
    throw new OAException("AK", "FWK_TBX_T_WF_UNEXPECTED_TRANS");
    else // we've just completed the flow
    // Assuming the "commit" succeeds, we'll display a Confirmation dialog that takes
         // the user back to the main "Purchase Orders".
    /* String poNumber = (String)pageContext.getTransactionValue("PO_NUMBER");
    MessageToken[] tokens = { new MessageToken("PO_NUMBER", poNumber),
    new MessageToken("PO_APPROVER", pageContext.getUserName()) };
    OAException confirmMessage = new OAException("AK", "FWK_TBX_T_PO_CREATE_CONFIRM", tokens);
    OADialogPage dialogPage = new OADialogPage(OAException.CONFIRMATION,
    confirmMessage,
    null,
    pageContext.getApplicationJSP() + "?OAFunc=FWK_TOOLBOX_PO_SUMMARY_CR&retainAM=Y",
    null);
    pageContext.redirectToDialogPage(dialogPage);
    else if ("goto".equals(pageContext.getParameter(EVENT_PARAM)) &&
    "NavBar".equals(pageContext.getParameter(SOURCE_PARAM)))
    // Note that the OANavigationBean publishes a "goto" event paremeter when
    // either the Back or Next button is pressed. You need to determine which way to
    // go based on the related "value" parameter.
    // Also note the check of "source" above to ensure we're dealing with the
    // page-level navigation here and not table-level navigation which is
    // implemented with the same Bean configured differently.
    int target = Integer.parseInt(pageContext.getParameter("value"));
    String workflowResult;
    if (target < currentStep)
    workflowResult = "PREVIOUS";
    else
    workflowResult = "NEXT";
    String nextPage = OANavigation.getNextPage(pageContext, workflowResult);
    if (nextPage != null)
    HashMap params = new HashMap(1);
    params.put("ccStep", IntegerUtils.getInteger(target));
    pageContext.setForwardURL(pageContext.getApplicationJSP() + "?" + nextPage, // target page
    null,
    KEEP_MENU_CONTEXT,
    "", // No need to specify since we're keeping menu context
    params, // Page parameters
    true, // Be sure to retain the AM!
    ADD_BREAD_CRUMB_NO, // Do not display breadcrumbs
    OAException.ERROR); // Do not forward w/ errors
    else
    throw new OAException("AK", "FWK_TBX_T_WF_NO_NEXT_PAGE");
    else if (pageContext.getParameter("Cancel") != null)
    am.invokeMethod("rollbackCitizenInfo");
    // Remove the "in transaction" indicator
    TransactionUnitHelper.endTransactionUnit(pageContext, "citizenCreateTxn");
    pageContext.forwardImmediately("OA.jsp?page=/uttara/oracle/apps/uttaraimc/createcitizen/webui/CreateCitizenSearchPG",
    null,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    null,
    true, // retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
    How to resolve this issue?
    please suggest.
    Thanks & Regards,
    Sagarika

    Sagarika,
    Please go thru the dev guide which explains the train flow in the multistep update exercise. Compare the steps with ur implementation.
    - Senthil

  • Problems with OSX Mavericks - How do I return to previous operating system?

    I installed OS X Mavericks on my iMac. Now Safari, Mail, iPhoto, basically all software, hangs up as soon as it is opened. Nothing runs.
    Also I have this constant request for keychain password which I haven't set up. I tried the fix I found online, but as soon as I click on "mail preferences" Mail hangs up and I have to force quit the program.
    I have re-installed this software 3 times now. It has not functioned properly yet. Thank goodness Firefox still works.
    Any solutions out there?

    Apple doesn't seem to know how to "fix what's wrong".
    I spent about an hour yesterday with Apple Tech Support. No solution.
    I had a mbp running Mountain Lion and iPhoto 8.1.2. Perfect harmony.,
    I purchased a new mbp from Apple, running Mavericks. It has iPhoto 9.5.1 on it.
    When I started up iPhoto, it told me that my previous iPhoto library was not compatible and that I needed to "upgrade my iPhoto database"
    I click on that link, and iPhoto stops responding.
    Tech support walked me through various attempts at solving this problem, but all attempts failed.
    After about an hour, neither the original tech nor the supervisor who took over had figured out what to do.
    They told me that, as a last resort, they could save the photos in my old library and be able to use them with iPhoto 9.5.1, but I would lose all the organization (albums, folders). How is that acceptable, Apple? It's a big deal to me. They kept telling me that this was a very unusual case, but if you google "mavericks iphoto problem" you'll see lots of other people having Mavericks/iPhoto issues. They told me that I had a corrupted iPhoto database, but that database works just fine in Mountain Lion with iPhoto 8.1.2.
    Supervisor is supposed to call me Sunday afternoon to follow up on this ....

  • How can i execute multiple database operations using multiple objects

    i have data in files which i need to read/parse and insert/update the database. can someone tell me how can i read multiple statements at a time and process using multiple objects.

    This doesn't seem like too much of a JDBC question or at least the answer as I see it isn't unique or specific to JDBC.
    If you want to run multiple processes within your single program then you need to use Java threads. I would recommend you read up on how to properly code Java threads and if you have questions unique to your multi-threaded JDBC implementation come back and ask those questions.
    You may also want tot take advantage of a transaction manager that includes a database connection pool that will handle most of the complexity for you. Depending on the flexibility of your architecture you may not have to do any thread coding at all when using a transaction manager.

  • How to determine mobile operator used

    I have bought a second hand iPhone 4s. The seller did not know which operator used. I need this info in order to unlock the mobile and switch operator. How can I determine the old operator used?

    Go to settings, general, about, and see what it says for carrier. I would be concerned about a phone that I purchased where the person selling it did not know who the carrier was. Did they not know who they paid for sevice? I would not be surprised if you cannot use this phone.

  • Disabling attributes or operations using StandardMBean

    In the Best Practices document at http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/best-practices.jsp I find the following advice:
    If you need some particular abilities of Dynamic MBeans, for example the ability to supply descriptions for the attributes or operations, or the ability to disable certain attributes or operations, then you should consider subclassing javax.management.StandardMBean rather than implementing the DynamicMBean interface.
    I'm trying to learn about the various types of MBeans. Are there any details available on how to disable certain attributes or operations using a subclass of StandardMBean, and does anyone have a good use case for this feature?
    Thanks...

    Hi,
    Disabling attributes and operation is not something I would recommend, but if
    you need to do it it should be relatively easy to use javax.management.StandardMBean
    for that.
    For instance if you want to disable invoke for a given MBean, you could
    write a subclass of StandardMBean and override its invoke method to do something
    like:
    @Override
    public Object invoke(String methodName, Object[] params, String signature)
               throws ... {
       // disable method whatever
       if (methodName.equals("whatever"))
          throw UnsupportedOperationException("method whatever is disabled");
       // allows other methods
       return super.invoke(methodName,params,signature);
    }For background reading see:
    javax.management.StandardMBean: When and Why.
    http://blogs.sun.com/jmxetc/entry/javax_management_standardmbean_when_and
    -- daniel
    http://blogs.sun.com/jmxetc

  • How will include next cluase to our present tablespace

    Hi,
    I have add datafile to our tablespace , but by mistak i have not include NEXT clause
    how will include next clause.
    i have use following command
    alter database datafile '/oradata/ocr1.dbf' next 100M;
    alter database datafile '/oradata/ocr1.dbf' next 100M
    ERROR at line 1:
    ORA-01916: keyword ONLINE, OFFLINE, RESIZE, AUTOEXTEND or END/DROP expected

    I will got the answer
    alter database datafile '/oradata/ocr1.dbf' autoextend on next 100M;

  • SetProperty using struts

    How can we achieve this using struts?
    <jsp:useBean id="aaa" class="mypackage.Department"> <jsp:setProperty name="aaa" property="name" value="jsmith" /> <jsp:setProperty name="aaa" property="phoneNumber" value="555-5555" /></jsp:useBean>

    Below is the code of what I am doing.
    <bean:define id="offsetBean" name="coursePageForm" property="index" type="java.lang.Integer"/>
    <logic:iterate id="MapEntry" name="pageMap" length="1" indexId="india01">
    <bean:size id="mapSize" name="pageMap"/>
    <logic:iterate id="pageEntry" name="MapEntry" length="1" offset="offsetBean" indexId="india02">
    <bean:size id="pageSize" name="MapEntry"/>
    <td align="left" width="25%" >
    <bean:write name="pageEntry" property="pageText"/>
    </td>
    <TD align=right vAlign=top width=185>
    <html-el:img src="${pageEntry.pagePic}" />
    </TD>
    </logic:iterate>
    </logic:iterate>
    My site enables users to take online courses. Every course has a course Id and based on that course id, every course has multiple sections with section ids. Each section has multiple pages, with Page Id's.
    When a user clicks on a course I get all the sections and pages related to that section from the database. Each section is stored as one entry in an ArrayList and since each section has multiple pages that are also stored as ArrayList inside this ArrayList. So I have an ArrayList of section containing ArrayList of pages.
    I have one page to display all the contents. I loop through the ArrayList the way it�s shown above. Every time the user clicks next I increment the inner Loop's "offset" attribute. The problem starts when all the pages of a section are done and now we need to move to the next section. For that I want to increment the "offset" attribute of outer loop. I don't know of an easy way of doing this.
    We can communicate over the email also.
    [email protected]

Maybe you are looking for