• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp database connection

 
aman hindustani
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all...

why don't we prefer to create a connection to database in jsp .
 
Pratibha Malhotra
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hindustani

You can no doubt do it. Its doeable also. Infact this is what use to happen in Model 1.

But the question is to provide the best/optimized/scalable....... solution for a problem.

MVC Model 2 gives one such solution, where in
Jsp -> Servlet -> Facade -> DAO -> Database

why don't we prefer to create a connection to database in jsp .


In case you have more doubts, feel free to ask
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what is your answer?
am i reducing the performance of application
or am i increasing the complexity of the application by following the mvc1 architecture

am i going for illegal architecture
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are meant for display logic. You shouldn't put any business logic / database code in it. Seperating Model, View and Controller makes your application more maintainable.
 
abhishek gowlikar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not true that we cannot connect Db from jsp,But it is not a preferable approach:

jsp--->Db like tier 1 model
jsp--->servlets---->dataobjects--->Database MVC Model

Modelata Objects
View: always The presentation layer have light component(this is the reason we make a Db connection at the Backend may be in DAO or Servlets)
Controller:Here Controller is a Servlets Actions
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me make it clear.

Model 1 is not MVC
Model 2 is also known as MVC

Think about few of these factors you will get your answer.
- code complexity
- maintenance nightmares (includes adding new features, fixing or modifying previous code)
- reusability
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!