How to retrieve and store data in a web application


General J2EE: How to retrieve and store data in a web application

  1. How to retrieve and store data in a web application (2 messages)

    Presently working on a search and listing page. The search may retrieve an ArrayList of data but on the list page, oni a limited 10 lists of data will be shown. Does anyone noe how do i keep the rest of the data so that when user click "next" list of data, i can display the next few data in the listing page? have used set and get attribute to display the 1st set of results but when i use get attribute again... it return null.

    thks in advance...
  2. if you are using just jsp/servlets, you will need to put the arrayList into HttpSession object.

    if you are using JSF, you can use managed-beans with session scope.

    or if using some sort of ORM will be similar as well.

    or if going stateless, and if the list is small,
    you can stringfy (either the data, or html representation) the data in a hidden input field so that you can pass it from one page to another.

    or a ghetto way is to keep track of the page you are on
    in a hidden input field, and every time they switch a page, take a hit on the db w/ a sql query that needs the page to be passed in.
  3. The ArrayList data that you store in request is stored only for the request Scope. To use the same Object on multiple pages you should store the Object in session.

    request.getSession().setAttribute("mylist", listObj);


    This object stays as along the session is valid. If this Object is very large then you should consider clearing this object after use.