0

I have a PHP background and now I am a JSP/Servlet beginner.

I have a doubt about the approach I need to use, for example, let's say I have a dynamic list of items, i can implement in two ways with JSP

  1. Reading the list of items from a database
  2. Reading the list of items from a Collection inside an Object

Is the first the right approach? Or is there any case where you need to use the second one?

1
  • do you mean in first approach, directly access DB from JSP ? Mar 24, 2013 at 22:23

1 Answer 1

0

First of all, I certainly wouldn't recommend reading the list from a database directly into a JSP. Best practice would involve a layer of your application (e.g. a DAO) that would read from the database into a collection that would be passed to another layer that would render the view.

If the set of values is significantly long, and/or may change often, than of course it should be in the database (examples: a list of countries available when filling out an address, a list of products, a list of agents to whom a ticket may be assigned).

However, for a shorter list, that is primarily used to provide possible values (where the values may end up in the database, but the list of values itself need not be), an Enum may be a better choice (examples: a list of possible statuses for a ticket (open, pending, solved, closed), a list of types for a phone number (home, work, mobile)).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.