Search code examples
javajsparraylistjavabeans

Why we use arraylist to store java bean in jsp?


in jsp why we use arraylist to store javabean and what happens without using arraylist to use javabean in jsp during jdbc connectivity. in many source codes i have seen that javabean is stored in arraylist and then accessed in jsp.


Solution

  • In many cases one does not make direct JDBC calls from within JSPs/Servlets and such. It depends on the architecture of an application.

    E.g. if a JSP or Servlet accesses the database through an EJB, the database session gets lost when returning from the EJB call (because it's bound to a transaction), thus making it necessary to buffer values (most likely beans) in some kind of collection. An ArrayList provides very fast random access and is also very compact (because it's backed by an array), so it's a natural choice of most programmers.