0

Basically that's the question and here are two examples of code to compare the difference between DAO calls from JSP (1) and the (2) that is extended way and redundant. When I question about what's better I'm talking about the quality of software development.

(1) Is this right way to go?:

JSP:
DaoObject t = new DaoObject();
t.listObjects();

(2) Or is best this?:

JSP:
Object t = new Object();
t.listObjects();

Model:
class Object { ...
public ArrayList<Object> listObjects()
{
    DaoObject t = new DAOObject();
    return t.listObjects();    
} ... }
Sequoya
  • 433
  • 4
  • 16

3 Answers3

0

From the design point of view, the solution (2) is better. Your DAO object may not be necessary the same with your presentation object, the model for your user interface. It can be even composed of more DAO objects.

S.Stavreva
  • 577
  • 4
  • 8
0

Its wrong practice to make DAO calls from JSP, According to MVC pattern , you should use JSP as a View, there will be a model consisting of getters and setters i.e. java POJO class. Also there will be a controller - a component which is responsible for communication between model and view.
A user always sees the view and communicates with the controller. The values entered by user will be submitted from the view and are set to the model, which in turn will be used by the controller in backend.

arjun99
  • 358
  • 1
  • 8
0

For that kind of operation you must use the JSTL functions. For jsp, as the previous comment explains it must have a view behavior. Explore how to use it, it is clean and simple to use.

langeles86
  • 162
  • 1
  • 12